Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jujule · Sep 28, 2012 at 01:50 PM · c#stringencodingunicodechar

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.

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jessespike · Sep 28, 2012 at 04:29 PM 0
Share

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.

avatar image jujule · Sep 28, 2012 at 05:01 PM 0
Share

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.

avatar image Jessespike · Sep 28, 2012 at 05:35 PM 0
Share

Windows 7 64bit Unity 3.5.5f3

avatar image jujule · Oct 02, 2012 at 03:28 PM 0
Share

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.

avatar image Shivam_Dhoot · Jan 22, 2015 at 08:59 AM 0
Share

I know its pretty late but still::::::::::save in unicode no authentication required encoding visual studio provides this.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges