how to convert unicode to int in C#?
-
Hi, i have a unicode string in arabic language. i want to convert it to its integer value. but when i use Convert.Int32(unicodestring). it raises exception that the input is in invalid format. please guide me how to convert unicode string to int. Regards, Omar Lodhi
-
Hi, i have a unicode string in arabic language. i want to convert it to its integer value. but when i use Convert.Int32(unicodestring). it raises exception that the input is in invalid format. please guide me how to convert unicode string to int. Regards, Omar Lodhi
Posting the relevant code sample would be helpful. Also, you can try Int32.Parse().
Cheers, Vikram.
The cold will freeze our stares We won't care...
-
Hi, i have a unicode string in arabic language. i want to convert it to its integer value. but when i use Convert.Int32(unicodestring). it raises exception that the input is in invalid format. please guide me how to convert unicode string to int. Regards, Omar Lodhi
How many characters in the string? Maybe thats the problem? Perhaps you need to ittereate through each character of the string in turn, something like:
foreach( char character in unicodeString ) { int charValue = Convert.ToInt32( character ); }
Just an idea. If your still stuck, you should post some of your code.
Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students View my Blog
-
How many characters in the string? Maybe thats the problem? Perhaps you need to ittereate through each character of the string in turn, something like:
foreach( char character in unicodeString ) { int charValue = Convert.ToInt32( character ); }
Just an idea. If your still stuck, you should post some of your code.
Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students View my Blog
Hi, i have to convert a unicode string to its hex equilent. i have converted this from a VB6 code that uses AscW() method to convert unicode to a integer value and then to Hex value. Here is code String strSrc="جمل هندسة في الدنيا أن تبني جسرا من الأمل على بحر من اليأس.."; strResult = ""; for (int i = 0; i < strSrc.Length; i++) { try { //tried this one get exception //nVal = Int32.Parse(strSrc.Substring(i, 4)); //tried also statement below also get exception nVal = Convert.ToInt32(strSrc.Substring(i, 4)); strHex = Convert.ToString(nVal, 16); strResult += strHex; } catch (FormatException e) { ; } } Exceptoin error string is "Input was not in correct format" Thanks and Regards, Omar
-
Hi, i have to convert a unicode string to its hex equilent. i have converted this from a VB6 code that uses AscW() method to convert unicode to a integer value and then to Hex value. Here is code String strSrc="جمل هندسة في الدنيا أن تبني جسرا من الأمل على بحر من اليأس.."; strResult = ""; for (int i = 0; i < strSrc.Length; i++) { try { //tried this one get exception //nVal = Int32.Parse(strSrc.Substring(i, 4)); //tried also statement below also get exception nVal = Convert.ToInt32(strSrc.Substring(i, 4)); strHex = Convert.ToString(nVal, 16); strResult += strHex; } catch (FormatException e) { ; } } Exceptoin error string is "Input was not in correct format" Thanks and Regards, Omar
Sorry, mate; I don't know any Arabic, so I have no idea if the string you have is a valid numeric string. If what you have is indeed a VALID numeric string in Arabic, perhaps the problem is the locale/culture settings. Int32.Parse() and Convert.ToInt32() both have various overloads - why don't you check them out? Pay special attention to the ones that take a CultureInfo parameter. Also, given Arabic is an RTL language, are you sure Substring() is returning the correct substring?
Cheers, Vikram.
The cold will freeze our stares We won't care...
-
Sorry, mate; I don't know any Arabic, so I have no idea if the string you have is a valid numeric string. If what you have is indeed a VALID numeric string in Arabic, perhaps the problem is the locale/culture settings. Int32.Parse() and Convert.ToInt32() both have various overloads - why don't you check them out? Pay special attention to the ones that take a CultureInfo parameter. Also, given Arabic is an RTL language, are you sure Substring() is returning the correct substring?
Cheers, Vikram.
The cold will freeze our stares We won't care...
Hi, i think RTL is only for displaying data. in case of string storage it is stored just same as normal string. this code is working in VBA that reads unicode converts unicode string to hex format. do you know any method equivalent to VB method AscW for getting code of any unicode character. Thanks, Omar