0


Edit 04/04/11: It turns out that the UTF encoding was just hiding a bigger problem. I initially thought it was the UTF encoding as setting that seemed to solve the search problem, but it was more to do with how mongodb was serialising the search key in the background

I'm using Flash to create a small tool to generate db info for mongodb. It will generate something like:

db.save({"className":"mypackage.MyClass","name":"someName"});

And display that in a TextField so I can just copy and paste it directly into the db.

My problem comes with mongodb being unable to find that info later. After much debugging, the problem boiled down to the text not being entered in UTF-8 format. i.e., in order to make it work, I'd have to copy the line of text from Flash, paste it into something like Notepad++, set the encoding to UTF-8, then copy that text into the db.

So my question is this: is there a way to either specify that I want to generate the text as UTF-8 or copy as UTF-8 from the TextField to avoid having to have this extra step in my workflow.

Thanks

divillysausages
  • 7,883
  • 3
  • 25
  • 39

2 Answers2

1

This is just a thought.

Have you tried a byteArray.

        var b1:ByteArray = new ByteArray();
        var b2:ByteArray = new ByteArray();

        var a:String = "className";
        var b:String = "mypackage.MyClass";
        // supported UTF-8 codes are
        // unicode-1-1-utf-8, 
        // unicode-2-0-utf-8, 
        // x-unicode-2-0-utf-8
        b1.writeMultiByte(a, "unicode-1-1-utf-8");

        /**
        Writes a UTF-8 string to the byte stream. Similar to the writeUTF() method,
        but writeUTFBytes() does not prefix the string with a 16-bit length word.
        */
        b2.writeUTFBytes(b); // encodes straight to UTF-8

        // flash says it honors the encoding mark when using toString
        trace(b1.toString(), b2.toString());

supported char sets can be found at: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/charset-codes.html

Feltope
  • 1,098
  • 6
  • 9
  • I've tried it but not had much luck. Though, there might be a problem with my setup as it seems a bit random getting the data in even if I do it the right way. I have to look into it more on monday – divillysausages Apr 01 '11 at 17:11
  • The problem was something different (see question edit), but +1 for showing me something I didn't know. thanks again – divillysausages Apr 04 '11 at 17:13
1

Check out How does "cut and paste" affect character encoding and what can go wrong?.

In a comment someone mentions that, at least on Windows, the clipboard contains different versions of the copied text. It seems the problem is in the app that gets the pasted text (your db).

I've just tried pasting from a TextField into Notepad++ (previously changed the doc enconding to utf-8) and the text came out fine. So, it seems the problem is in the app that receives the text. Maybe you could use some escaping ( like \u00F1 for ñ) but I'm not sure whether that works or not, since I haven't used mongodb.

Community
  • 1
  • 1
Juan Pablo Califano
  • 12,213
  • 5
  • 29
  • 42
  • in fact, the app that receives the text is just a cmd shell. I copy my text, then right-click on the window title and go Edit > Paste. This should have the same effect as just typing in the commands by hand – divillysausages Apr 01 '11 at 16:33
  • @divillysausages. Not sure what's going on, since I don't know much about how Windows works, that's why I referred to the other question. For what is worth, I just tried copying text from a flash textfield into a cmd shell and the characters look fine (with the test string "AÑO"). – Juan Pablo Califano Apr 01 '11 at 17:45
  • I'm accepting this as the answer even though my problem was different, as it's what corresponds most to the question – divillysausages Apr 04 '11 at 17:12