appending "\" to a string
-
How do i append the character \ to a string rtf = rtf + @"\"; this is not working now is this rtf = rtf + "\\"; neither this rtf = rtf + "\"; Thank you.
Both of the first two work fine for me. 3rd one won't work because the \ sign is escaping the second " so you never actually close the quotes.
Simon
-
How do i append the character \ to a string rtf = rtf + @"\"; this is not working now is this rtf = rtf + "\\"; neither this rtf = rtf + "\"; Thank you.
-
Both of the first two work fine for me. 3rd one won't work because the \ sign is escaping the second " so you never actually close the quotes.
Simon
-
Thank you for me the first two lines are adding two // but i want only 1 and the last one is an escape char.
Are the two \'s appearing in your output, or only in the debugger? The latter will of necessity show slashes used as escape characters when you look at a string. If it's the former, you need to provide a small program that reproduces this so we can see what you';re doing wrong.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
-
Thank you for me the first two lines are adding two // but i want only 1 and the last one is an escape char.
-
How do i append the character \ to a string rtf = rtf + @"\"; this is not working now is this rtf = rtf + "\\"; neither this rtf = rtf + "\"; Thank you.
\ is an escape character both in C# and RTF, so you'll have to escape it twice. rtf = rtf + @"\\"; or rtf = rtf + "\\\\";
-
Its because you are viewing it in the debugger I suspect. If you just hover the mouse over it it shows \\, but if you look at it using the text visualiser it will be correct. Its caught me out before...
Bob Ashfield Consultants Ltd
Thank you all for your assistance Yes im viewing in the debugger, my problem is i want to search for a string and replace it with another but on the one im searching i want to append the "\" to it. like string str = @"\\"; string rtf1 = rtf.Replace("alt=\"\" src=\"/Web%20Cleint/Home%20Page/Images/Stop.png\"", rep); rtf = rtf.Replace(MatchList[i].ToString() + str.Substring(1,1), rep); on rtf1 there is a "\" after the pgn. but MatchList[i].ToString() doesnt have the "\" and i cant include it in my search(regx) as well.
-
How do i append the character \ to a string rtf = rtf + @"\"; this is not working now is this rtf = rtf + "\\"; neither this rtf = rtf + "\"; Thank you.
Thank you all for your assistance Yes im viewing in the debugger, my problem is i want to search for a string and replace it with another but on the one im searching i want to append the "\" to it. like string str = @"\\"; string rtf1 = rtf.Replace("alt=\"\" src=\"/Web%20Cleint/Home%20Page/Images/Stop.png\"", rep); rtf = rtf.Replace(MatchList[i].ToString() + str.Substring(1,1), rep); on rtf1 there is a "\" after the pgn. but MatchList[i].ToString() doesnt have the "\" and i cant include it in my search(regx) as well.
-
How do i append the character \ to a string rtf = rtf + @"\"; this is not working now is this rtf = rtf + "\\"; neither this rtf = rtf + "\"; Thank you.
rtf = "Testing Image Embading
\r\n
\r\nEmage Embabeded here\r\n" Regex exp = new Regex(@"img (alt=\.)?([^\.]+)\.png", RegexOptions.IgnoreCase); string InputText = rtf; MatchCollection MatchList = exp.Matches(InputText); Match FirstMatch = MatchList[0]; for (int i = 0; i < MatchList.Count; i++) { string str = @"\"; string rtf1 = rtf.Replace("alt=\"\" src=\"/Web%20Cleint/Home%20Page/Images/Stop.png\"", rep); string strToReplace; //= MatchList[i].ToString(); //;+ str; //strToReplace = strToReplace.Substring(0, strToReplace.Length); strToReplace = string.Format(@"{0}\", MatchList[i].ToString()); rtf = rtf.Replace(strToReplace, rep); i hard corded rtf1 and it worked fine so what i want is for strToReplace to be equal to this string Web%20Cleint/Home%20Page/Images/Stop.png\" and im trying to achieve that by using this string string strToReplace; //= MatchList[i].ToString() + str; it appends 2 \\ and doesnt match the other string I hope this will help.