# Using unicode in Juce

**URL:** <https://forum.juce.com/t/using-unicode-in-juce/4328>\
**Category:** General JUCE discussion\
**Created:** [September 26, 2009, 3:15am UTC](https://forum.juce.com/t/using-unicode-in-juce/4328 "2009-09-26T03:15:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![xsd121](https://avatars.discourse-cdn.com/v4/letter/x/ebca7d/32.png) [@xsd121](https://forum.juce.com/u/xsd121)\
**Post date:** [September 26, 2009, 3:15am UTC](https://forum.juce.com/t/using-unicode-in-juce/4328/1 "2009-09-26T03:15:45Z")

</div>

When the flag “JUCE\_STRINGS\_ARE\_UNICODE” is set, it means all string variables in app are now in unicode?

I got some problems here. I’m getting file infos(aritst, title, album…) from mp3 files, but can’t handle those “Far East Characters” correctly.

```auto
String a;
File file(T("d:/testHaro/夏夕空.mp3")); //a mp3 with Far East Chars
	if (file.existsAsFile())
	{
		FileInputStream stream(file);
		int i = 0; //tag and title
		
		stream.setPosition(stream.getTotalLength() - 128 + i);
		a += stream.readEntireStreamAsString();
		
		i = 33; //artist start point
		stream.setPosition(stream.getTotalLength() - 128 + i);
		a += stream.readString() + " ";

		i = 63; //album start point
		stream.setPosition(stream.getTotalLength() - 128 + i);
		a += stream.readEntireStreamAsString() + " ";

		i = 93; //year start point
		stream.setPosition(stream.getTotalLength() - 128 + i);
		a += stream.readEntireStreamAsString() + " ";

		i = 97; //comment start point
		stream.setPosition(stream.getTotalLength() - 128 + i);
		a += stream.readEntireStreamAsString() + " ";
}

```

[size=150]The result is "TAGϦ?Т= =O#/Ϧ? 2008 "[/size]

readEntireStreamAsString() is defined as:

This will read from the stream’s current position until the end-of-stream, and will try to make an educated guess about whether it’s unicode or an 8-bit encoding.

But I faile to get the correct characters.  
Someone can help me.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [September 26, 2009, 7:38am UTC](https://forum.juce.com/t/using-unicode-in-juce/4328/2 "2009-09-26T07:38:36Z")

</div>

i had a similar problem with encoding from and to CP1250, juce will not handle this you need to convert it manually, using ICONV or some sort of conversion table. Since i only had to deal with CP1250 i wrote a simple conversion table and it worked, however if your dealing with different encodings you’ll propably need iconv.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 26, 2009, 8:50am UTC](https://forum.juce.com/t/using-unicode-in-juce/4328/3 "2009-09-26T08:50:47Z")

</div>

> [@](#):
>
> When the flag “JUCE\_STRINGS\_ARE\_UNICODE” is set, it means all string variables in app are now in unicode?

Yes, they’ll all work fine internally. But what’s actually in the file you’re trying to read? Is it unicode, utf8 or some other code-page…? readEntireStreamAsString() isn’t very smart - if it doesn’t find unicode header byte markers, it’ll just pull it in as utf8.

---

<div class="post-metadata">

**Author:** ![xsd121](https://avatars.discourse-cdn.com/v4/letter/x/ebca7d/32.png) [@xsd121](https://forum.juce.com/u/xsd121)\
**Post date:** [September 27, 2009, 2:25am UTC](https://forum.juce.com/t/using-unicode-in-juce/4328/4 "2009-09-27T02:25:36Z")

</div>

I want to read the artist, the album name etc…

Let’s say another case:

I want to get the file’s path from the commandLine when the app is intialized,

```auto
void initialise (const String& commandLine)
    {
        helloWorldWindow = new HelloWorldWindow();
		helloWorldWindow->cpt->d = commandLine;
    }
```

where d is another String,  
the paths with CJK(chinese, japanese, korean) characters can’t be loaded.  
What transform work should I do?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 27, 2009, 6:55pm UTC](https://forum.juce.com/t/using-unicode-in-juce/4328/5 "2009-09-27T18:55:03Z")

</div>

Ok, but that’s a completely different matter - if it’s not correctly reading the command line args, I’d need to look at that, but which platform is it?

---

<div class="post-metadata">

**Author:** ![xsd121](https://avatars.discourse-cdn.com/v4/letter/x/ebca7d/32.png) [@xsd121](https://forum.juce.com/u/xsd121)\
**Post date:** [September 27, 2009, 11:36pm UTC](https://forum.juce.com/t/using-unicode-in-juce/4328/6 "2009-09-27T23:36:45Z")

</div>

Well,win32 xp

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 28, 2009, 8:18am UTC](https://forum.juce.com/t/using-unicode-in-juce/4328/7 "2009-09-28T08:18:28Z")

</div>

The code deliberately get the command-line params as unicode - you can see this if you look in PlatformUtilities::getCurrentCommandLineParams().

I can’t really see how anything so simple could go wrong, but you could try stepping through that and see what happens in there. Perhaps see if GetCommandLineW() is actually returning the characters you expect?
