Search Unity

TextAsset and encoding

Discussion in 'Scripting' started by perlohmann, Jan 26, 2010.

  1. perlohmann

    perlohmann

    Joined:
    Feb 12, 2009
    Posts:
    221
    Can anybody tell me if TextAsset will remove any non 7-bit ascii characters from its contents?

    I have a txt file with some danish letters æøå and some more european letters like é ö ü etc.

    I have of course assigned this txt file to a TextAsset property in the inspector. When I try and get the contents of the TextAsset from the code it returns a string with only the standard 7-bit ascii letters.
    Even when I try and use the byte array from the TextAsset class I cannot see any signs of the characters. When I output the byte values of the byte array there are no values higher 127 (7-bit ascii)

    Does anyone know a workaround other than pasting text directly into a string property through the inspector or by pasting it into the code?

    //perlohmann
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    sure you stored the file as UTF-8?
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    TextAsset definitely doesn't remove anything...indeed you probably didn't save in UTF8.

    --Eric
     
  4. perlohmann

    perlohmann

    Joined:
    Feb 12, 2009
    Posts:
    221
    yep default save of notepad is ansi. selected utf-8 and problem solved.

    thx
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    glad it worked :)

    Also, just because its much nicer and faster to work with: Have a look at programmer's notepad 2 ;)