String characters


#1

What I’m doing is capturing input from a TextEditor and converting it into a const char* which is then inserted into a mysql database with it’s library functions. However I am struggling to get it to hold certain characters.

For example, someone types in and is stored as a String called inputString:

[quote]Rand/$ 7.1500
Rand/£ 14.0700
Rand/€ 9.4600
Gold/oz $685.90[/quote]

Then the program places it into an INSERT sql statement, and finally the String is converted to a const char*:

query.execute((const char*)inputString);

Something goes wrong somewhere, because the above info really does not ever get placed into the database. I presume it’s struggling with the pound and euro symbols.

What exactly is going on? Any one have any work arounds? Do I need to escape the special characters? If so, can I suggest a getEscapedString() function for the String class.

Thanks for the help.


#2

You don’t really want to convert it to a char* - it’d be better if you could send it to your DB in unicode. Or maybe the DB is expecting utf8, in which case you could use the String::toUTF8 method?


#3

Alright, I’ll give the toUTF8 function a try. However, when I retrieve data from mysql, it returns it as a char*. What would I need to do to the returned char* to keep it in a unicode format?


#4

well if it is actually utf8 (you should double-check that it is), then you’d use the String::fromUTF8 to turn it back into a string.


#5