split issue
-
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();
}string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";
s=DecodeUnicode(s);I am using above code to remove "\\" into "\". But if we add some text in this string its gives error.
e.g.:string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930 abc";
error msg shows: Input string doesn't match. i think this issue occur due to, i divide substring(2,4) please guide me. thanx
-
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();
}string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";
s=DecodeUnicode(s);I am using above code to remove "\\" into "\". But if we add some text in this string its gives error.
e.g.:string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930 abc";
error msg shows: Input string doesn't match. i think this issue occur due to, i divide substring(2,4) please guide me. thanx
if your input string does not consist only of
\\uddd
sequences (where each d is a digit), then you need to search for such substrings and replace them one by one by the character they represent. :)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.
-
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();
}string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";
s=DecodeUnicode(s);I am using above code to remove "\\" into "\". But if we add some text in this string its gives error.
e.g.:string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930 abc";
error msg shows: Input string doesn't match. i think this issue occur due to, i divide substring(2,4) please guide me. thanx
Well, first... If you type this:
string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";
Then the compiler is already converting the double-backslashes to single-backslashes... But assuming you actually have the doubles in the string... Try just using
string.Replace()
...s = s.Replace(@"\\",@"\")
The @ sign before the first quote tells C# to ignore the escape characters (Including things like newlines and tabs)... You could also write
s.Replace("\\\\","\\");
Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels) -
Well, first... If you type this:
string s="\\u092A\\u094B\\u0937\\u093E\\u0939\\u093E\\u0930";
Then the compiler is already converting the double-backslashes to single-backslashes... But assuming you actually have the doubles in the string... Try just using
string.Replace()
...s = s.Replace(@"\\",@"\")
The @ sign before the first quote tells C# to ignore the escape characters (Including things like newlines and tabs)... You could also write
s.Replace("\\\\","\\");
Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels)Hi Ian, this is yet another episode in a long story, I still don't know what his application is about, but I think of it as some sort of compiler, where the input actually does contain double slashed codes, and needs to treat the escapes. In the current post, the double backslashes are present inside some string which should not have been displayed as a string literal; proof of that is it all worked well until he appended "abc". I'm afraid he is still not really grasping what the escape mechanism does and doesn't do. :)
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 Ian, this is yet another episode in a long story, I still don't know what his application is about, but I think of it as some sort of compiler, where the input actually does contain double slashed codes, and needs to treat the escapes. In the current post, the double backslashes are present inside some string which should not have been displayed as a string literal; proof of that is it all worked well until he appended "abc". I'm afraid he is still not really grasping what the escape mechanism does and doesn't do. :)
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.
Well, Replace is still easier :)
Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels)