special character replacement
-
The code I added does work, I checked it, and it is part of the language specification! If you want to output \ you need to use "\\" or @"\" If you want to output \\ you need to use "\\\\" or @"\\" The @ character switches the escaping off. If you are still having problems, I suggest you post more of your code, something else might be happening!
ragnaroknrol The Internet is For Porn[^]
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners. -
hi how can i replace "\\" with "\". because i am using, String.Replace("\\","\"); but it does not work. thanx
-
Is that your actual code? working example...
string s = @"some\\text";
s = s.Replace(@"\\", @"\");
//s should now = "some\text";Life goes very fast. Tomorrow, today is already yesterday.
Actually i am using xml file. In my xml file contains following text: \u092A\u094B\u0937\u093E\u0939\u093E\u0930 and i want to convert in correspponding letter through httpUtility.htmlEncode(). when i put above code in htmlEncode function, it works properly. when i retrieve this in C# as string it shows like: \\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930. so this is not convert. please guide me.
-
hi how can i replace "\\" with "\". because i am using, String.Replace("\\","\"); but it does not work. thanx
Why do you need to?
-
Actually i am using xml file. In my xml file contains following text: \u092A\u094B\u0937\u093E\u0939\u093E\u0930 and i want to convert in correspponding letter through httpUtility.htmlEncode(). when i put above code in htmlEncode function, it works properly. when i retrieve this in C# as string it shows like: \\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930. so this is not convert. please guide me.
If you are simply looking at the value in the debugger, then those extra back-slashes aren't really there, don't worry about them.
-
Why do you need to?
-
i WANT TO RETRIEVE EQUIVALENT VALUE OF THE GIVEN STRING. THE ABOVE CODE VALUE IN SEE IN HINDI IS "POSHAHAR".
OW! My eyes!
-
OW! My eyes!
And ears...... It turns out the code I posted demonstrating the difference between
Console.WriteLine("\\");
Console.WriteLine(@"\\");doesn't work. There goes ~10 years of .net experience perhaps I should go back to asking people to switch it off and on again for a living :-)
ragnaroknrol The Internet is For Porn[^]
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners. -
hi how can i replace "\\" with "\". because i am using, String.Replace("\\","\"); but it does not work. thanx
ahmad25 wrote:
it does not work
that is not informative at all. if you want a good answer, then provide quality information to begin with. Don't say "it does not work", specify what kind of problem there is (compilation error, run-time error, ...) and be specific (error number, exception message, line number, etc). :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
ahmad25 wrote:
it does not work
that is not informative at all. if you want a good answer, then provide quality information to begin with. Don't say "it does not work", specify what kind of problem there is (compilation error, run-time error, ...) and be specific (error number, exception message, line number, etc). :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
this is my string: \u092A\u094B\u0937\u093E\u0939\u093E\u0930
i used this code:string unicodeString = HttpUtility.HtmlEncode("\u092A\u094B\u0937\u093E\u0939\u093E\u0930");
MessageBox.Show(unicodeString);it gives me answer correct as "POSHAHAR" IN HINDI FONT. BUT if we use above text as string it gives
string unicodeString = HttpUtility.HtmlEncode(above_code);
MessageBox.Show(unicodeString);the string takes value in this form: "\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";
so, it can't work. then my problem is , how am i replace "\\" instead of "\".
-
this is my string: \u092A\u094B\u0937\u093E\u0939\u093E\u0930
i used this code:string unicodeString = HttpUtility.HtmlEncode("\u092A\u094B\u0937\u093E\u0939\u093E\u0930");
MessageBox.Show(unicodeString);it gives me answer correct as "POSHAHAR" IN HINDI FONT. BUT if we use above text as string it gives
string unicodeString = HttpUtility.HtmlEncode(above_code);
MessageBox.Show(unicodeString);the string takes value in this form: "\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";
so, it can't work. then my problem is , how am i replace "\\" instead of "\".
It is not as you said: in C# each string is unicode and something like "\u092A" is an escape sequence that mean "the unicode character with the code 0x092A. In other words, it is not a sequence of characters, but a single one.
-
this is my string: \u092A\u094B\u0937\u093E\u0939\u093E\u0930
i used this code:string unicodeString = HttpUtility.HtmlEncode("\u092A\u094B\u0937\u093E\u0939\u093E\u0930");
MessageBox.Show(unicodeString);it gives me answer correct as "POSHAHAR" IN HINDI FONT. BUT if we use above text as string it gives
string unicodeString = HttpUtility.HtmlEncode(above_code);
MessageBox.Show(unicodeString);the string takes value in this form: "\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";
so, it can't work. then my problem is , how am i replace "\\" instead of "\".
Hi, much better now, I understand you happen to have strings that hold Unicode characters in their \u format (as accepted by the C# compiler), and need them to be interpreted. I wasn't able to locate a .NET class that really supports this, so the best I could come up with is:
static string DecodeUnicode(string s) { StringBuilder sb=new StringBuilder(); while (s.Length!=0) { sb.Append((char)int.Parse(s.Substring(2, 4), NumberStyles.HexNumber)); s=s.Substring(6); } return sb.ToString(); }
which only accepts strings that consist of groups of six characters (a backslash, a 'u', and 4 hex digits); you may choose to add checks and error handling. It works for your example.
string s="\\\\u092A\\\\u094B\\\\u0937\\\\u093E\\\\u0939\\\\u093E\\\\u0930"; log(s); s=DecodeUnicode(s); log(s);
FWIW: I think you got yourself into trouble; most of the time, you should simply avoid having to do this, and have the compiler translate those \uXXXX sequences into single characters! PS: I'm not sure what HttpUtility.HtmlEncode is doing for you. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Hi, much better now, I understand you happen to have strings that hold Unicode characters in their \u format (as accepted by the C# compiler), and need them to be interpreted. I wasn't able to locate a .NET class that really supports this, so the best I could come up with is:
static string DecodeUnicode(string s) { StringBuilder sb=new StringBuilder(); while (s.Length!=0) { sb.Append((char)int.Parse(s.Substring(2, 4), NumberStyles.HexNumber)); s=s.Substring(6); } return sb.ToString(); }
which only accepts strings that consist of groups of six characters (a backslash, a 'u', and 4 hex digits); you may choose to add checks and error handling. It works for your example.
string s="\\\\u092A\\\\u094B\\\\u0937\\\\u093E\\\\u0939\\\\u093E\\\\u0930"; log(s); s=DecodeUnicode(s); log(s);
FWIW: I think you got yourself into trouble; most of the time, you should simply avoid having to do this, and have the compiler translate those \uXXXX sequences into single characters! PS: I'm not sure what HttpUtility.HtmlEncode is doing for you. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.