- Home /
Finding a character unicode in C#
Hi,
I am trying to map characters in a c# string to a bitmap font in a texture. To do that, I resort to `System.Text.Encoding.Default.GetBytes ( myString )`. I then loop through all bytes and each byte value points to a set of uv coordinates in the texture. Everything works fine but for characters outside of the ASCII range.
I have tried to make my method a bit more subtle by getting each char of the string then getting the bytes for each of those chars. But I always get the first byte to 63 ( unicode for the question mark, I believe ) and a 0 for all non-ASCII characters in the string. I have put up the following method to illustrate my point :
public void TestGetUnicode () {
string s = "";
s += "Byte Count : " + System.Text.Encoding.Default.GetByteCount ( "è" );
s += " Bytes : ";
for ( int i = 0; i < System.Text.Encoding.Default.GetByteCount ( "è" ); i++ )
s += System.Text.Encoding.Default.GetBytes ( "è" )[i] + " ";
Debug.Log ( s );
}
Here is the result in the debug console :
Byte Count : 2 Bytes : 63 63
I have tried to save my files to every encoding available in MonoDevelop and replaced the call to the default encoding with all encodings described on the msdn .net documentation. Whatever the encoding I use to save the file and get the bytes from the string, I only get combinations of 0 and 63.
Does anybody know how to properly get the bytes from a c# string ?
Thanks in advance.
hmm interesting. I copied-paste the snippet and my console reports:
Byte Count : 2 Bytes : 195 168
I didn't do anything special. I made a fresh project, made a script, and pasted the code.
Thanks for trying it out. Strange indeed.
$$anonymous$$ay I ask what os and what version of Unity you are using? I am on a $$anonymous$$ac using Unity 3.5.3.
On an other $$anonymous$$ac, I downloaded the latest Unity version ( 3.5.6f4 ) and made a fresh project. No luck.
$$anonymous$$aybe it is a $$anonymous$$ac only problem. I'll fill a bug report.
I know its pretty late but still::::::::::save in unicode no authentication required encoding visual studio provides this.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to store a tab character in an inspector field 0 Answers
Generate Json from Class Type List 1 Answer
Converting 1s and 0s to float 1 Answer