replace ü,ä,ö

Hi!

I want to replace üäö with ue ae oe and have a weird problem: it just doesn’t do it…
my code is as follows:

Debug.Log(annotateTitle + “_” + annotateText);
// replace Umlaute
annotateTitle = annotateTitle.Replace(“ü”, “ue”);
annotateTitle = annotateTitle.Replace(“ö”, “oe”);
annotateTitle = annotateTitle.Replace(“ä”, “ae”);

annotateText = annotateText.Replace(“ü”, “ue”);
annotateText = annotateText.Replace(“ö”, “oe”);
annotateText = annotateText.Replace(“ä”, “ae”);
Debug.Log(annotateTitle + “_” + annotateText);

both debug logs are the same and the öäü are still in the string.

Any ideas?

Thanks
Gabriel

You might need to have your text editor save the scripts in UTF-16 or UCS-2 encoding. I did some brief experiments a while ago and came to the conclusion that scripts written in other encodings tend to not retain characters outside of the 7-bit ASCII range, so your accented characters might be turning into some other random characters that won’t be found in the strings you’re testing against.

I presume that there are other encodings that should be just as good, including UTF-8 with a BOM and whatever the compiler uses by default, but I wasn’t able to get them to work in my tests.

Perhaps we should write a large guide for quite some english speaking dev (especially US dev as it seems) which clearly points out that ASCII is 256 letters not their kiddie 128 letters they always restrict their trash (-> incorrect implemented) applications to grml

Looking into it a bit further, it seems that the mcs compiler’s default code page is “US-ASCII” on my system. I suppose that backs up what I said above, that you can expect anything above 7-bit ASCII to be altered or omitted in some way, unless the source file is in some easily determined encoding like UTF-16 / UCS-2 or UTF-8 with a BOM. Maybe this could be addressed by having Unity pass the -codepage:utf8 option when it calls mcs. Not sure whether the Javascript or Boo compilers have any features to handle this kind of thing, though.

I know what you mean, but ASCII is hardly a complete solution unless you’re only interested in supporting your own language. Even with Unicode support, it’s a complicated business to allow text entry in a wide variety of languages. How well do your games support Russian or Chinese? :wink:

Actually UTF-8 is perfectly fine for Russian, trust me I know. Behold Palestine in all it’s russian glory.
Sorry could resist, I’ll crawl back under my rock now.

hmmm, unfortunately it didn’t solve the problem. I openend the code file in TextMate and saved it as UTF-8. When after that opening the code file with unitron, I get strange character handling:

annotateTitle = annotateTitle.Replace(“ü”, “ue”);

The characters in turn still don’t get replaced in the strings…

Try UTF-16 (either endianness).

Finally! UTF-16 it is :slight_smile: