Converting std::string app to Unicode - use wstring or utf8?

(Not non-technical but not sure which forum to post on).

In my application originally developed in C++Builder 5, I mostly use "std::string" for strings; and I only convert to AnsiString at the point of interfacing with VCL functions.

Now when porting to XE5, I need to be able to interface with UnicodeStrings.

Generally speaking - is it better that I change all my code to use "std::wstring" ;  or should I continue to use "std::string" but do to/from UTF-8 conversion at the point of interfacing with UnicodeString?
0
Matt
5/29/2014 2:11:27 AM
embarcadero.cppbuilder.nontech 971 articles. 0 followers. Follow

1 Replies
662 Views

Similar Articles

[PageSpeed] 17

Matt wrote:

> Generally speaking - is it better that I change all my code to
> use "std::wstring" ;  or should I continue to use "std::string"
> but do to/from UTF-8 conversion at the point of interfacing
> with UnicodeString?

That is really up to you to decide based on your own needs.  If using UTF-8 
makes more sense then use UTF-8.  If using UTF-16 makes more sense then use 
UTF-16.  Generally, UTF-8 is more compact in most (but not all) languages. 
 On the other hand, most platform APIs are UTF-16.  So if you make a lot 
of API calls, UTF-16 may make more sense.  If you make mostly STL calls and 
fewer API calls, UTF-8 may make more sense.  It really depends on what your 
project is actually doing.

--
Remy Lebeau (TeamB)
0
Remy
5/29/2014 5:20:40 PM
Reply:

Similar Artilces:

How to convert a String into a UTF8 String
Hello! I want to convert a normal String into a UTF8 String for example:myString = BüromyUTF8String = Büros  I dont know how to do this. In PHP you can do this with myUTF8String = utf8_encode(myString) Thank you for all hints! try this string test ="ÁÉÍÓÚ áéíóú àèìòù äëïöü Ññ €"; byte[] a= System.Text.Encoding.UTF8.GetBytes(test); string test2= System.Text.Encoding.UTF8.GetString(a);  greetingsBest Regards,Sebastián DopicoBlog Desarrollador Thank you Sebastián! If I make it like that - test2 looks the same as test.But I think my problem is solved. (Someone tol...

Convert Unicode string to Readable String
Novell Identity Manager 3.5.1 RedHat Linux enterprise edition. SOAP IDM driver.. When I query on an attribute "firstName" from IDM, the application returns value on that atrribute as the "English\u00c6". It looks like the string comes as a Unicode string.. I need help to reformat that value so that it can be readable for my rules in my driver.. Any help guys? Regards, M. -- love anything that talks binary! ------------------------------------------------------------------------ On Fri, 21 May 2010 08:26:01 +0000, belaie wrote: >...

How to handle unicode strings in utf8 and pre-utf8 pragma perls
Hello I'd be grateful if someone could help me with this, as I know very little about Unicode. I currently have Unicode data stored as bytes, or escaped depending on the perl version, eg: my @day_names; if ( $] >= 5.006 ) { @day_names = ( "\x{0414}\x{04af}\x{0439}\x{0448}\x{04e9}\x{043c}\x{0431}\x{04af}", "\x{0428}\x{0435}\x{0439}\x{0448}\x{0435}\x{043c}\x{0431}\x{0438}", "\x{0428}\x{0430}\x{0440}\x{0448}\x{0435}\x{043c}\x{0431}\x{0438}", "\x{0411}\x{0435}\x{0439}\x{0448}\x{0435}\x{043c}\x{0431...

converting std::string to UnicodeString
I have a function that returns std::string and need to convert that to a Unicode string. I tried: String S=(UnicodeString(getname()); but I get an error that says "could not find a match for UnicodeString::UnicodeString(std::string)" I have some sample code that supposedly works that declares a variable and and sets it to the function return value like this: std::string name; name=getname(); if that helps any. thanks. > {quote:title=Kenneth Czepelka wrote:}{quote} > I have a function that returns std::string and need to convert that to a Unicode string. ...

How to convert Literal string to Unicode ?...
Hi, I want to convert literal string to unicode before insert into the database. and after insertion i want to retrive this value from data base and convert back to literal string. pls tell me how to incode and decode literal string to unicode and from unicode to literal string.Please remember to click “Mark as Answer” on the post that helps youJasim AkhtarNew Delhi ( INDIA ) what kind of character do you need to convert to unicode? I used to use "multi-string to wide char" windows API(sounds like that,not sure)  when i was a c++ developer, this api will convert a ASCII c...

How can I convert strings from UTF8 to Big5
HiMy db is mysql 4.x. It not supports utf8 format. But I can't convert utf8 to Big5.Can any one help me?Thanks a lot!! ...

UNICODE, wchar_t, jschar, std::wstring, ...
I'm trying to build a UNICODE version from my wxJS project. What's the best practice to do this? I started to use std::wstring but I found out that when I use JS_EvaluateUCScript that std::wstring is not compatible with jschar. Is there a way to convert to jschar? Is it safe to cast wchar_t to jschar? Or should I use some library like ICU? I'm new to UNICODE programming, so any help is welcome. Franky. Franky Braem wrote: > I started to use std::wstring but I found out that when I use > JS_EvaluateUCScript that std::wstring is not compatible with jschar...

convert octet string to string
I'm trying to use IDM 3.5.1 provision an AD environmnet with users from eDir. We wanna provision as much info as possible, but one attribute gives us headaches. This is an auxiliary attribute associated with each user in eDir that has it's syntax set to octet string. Problem is we need to provision this over to another attribute in AD that uses string as its syntax. Is thee a way through XPath or ECMA script to have the value converted during the provisioning? I've no experience with either XPath or ECMA so please be detailed in your replies. Thx -- jdoeconsu...

How to convert a unicode string between a textbox and an RDF literal
The XUL:textbox value property seems to return a DOMString that is UTF-16. If I store the textbox value to an RDF literal, which I think should accept UNICODE and later return the value back to the same textbox some characters e.g. a umlaut is shown as a question mark in a black diamond. What happened and how to correct it? I use Javascript. Marja ...

Converting a list of string into string
When I try the following code in Prism I get the error "Error 8 (CE15) Type mismatch, cannot assign array of System.String to System.String " ***************************************************************** var mobileNumberList :List<string> mobNumberArray :string Begin mobileNumberList.add('1234567890'); mobNumberArray := mobileNumberList.ToArray();//error here end; *************************************************************** What needs to be done to convert an array of strings to a string Venkatesh Venkatesh VT a écrit : > When I...

Convert string to string array.
Hi, We have a string array argument in datawindow object for 'IN' sql statement. Our user enter a string in a single line edit. How to convert the string to a string array for the argument of datawindow? ex. user input : 'A', 'B', 'C' => str_arr[]={'A', 'B', 'C'} dw_1.retrieve(str_arr) Thanks in advance. Take a look at the n_cst_string object in the pfc. It has a method called of_ParseToArray that does exactly what you're looking for. It's a pretty simple task to 'port' the code ...

Help!
Hi, The typecasting used with non unicode strings 'PChar(s)' doesn't work more correct with unicode strings in D2010. How can I do this? Thanks, John > The typecasting used with non unicode strings 'PChar(s)' doesn't work > more correct with unicode strings in D2010. How can I do this? If your question is 'how do I cast from a string to a PChar', then the answer is 'in exactly the same way as you did in D2-D2007'. Alternatively, if your question is 'how do I cast from an AnsiString to a PChar', then it depends on your unde...

D2010: How to write a unicode string to TMemoryStream as UTF8 bitstream?
Sorry guys if this a repeat question, but I have been struggling for two hours trying to get my head round this... How do you write a string (UnicodeString) to a TMemoryStream so that the stream data ends up as a UTF-8 bitstream? Many thanks in advance... > How do you write a string (UnicodeString) to a TMemoryStream so that > the stream data ends up as a UTF-8 bitstream? Assign it to a UTF8String, and pass out the resulting character data - {code} procedure WriteUTF8(Stream: TStream; const Str: string; SendBOM: Boolean = False); const UTF8BOM: array[1..3] of Ansi...

Convert UTF8 string to ISO-8859-2 in VB
Hi I have a string in UTF8. I want to have the string in UTF-8 but in one case in the code I need to have it in ISO-8859... how? Please help!! Thx!! /Staffan   string stringutf = string.Empty; Encoding SourceEncoding = Encoding.GetEncoding("ISO-8859-2"); Encoding TargetEncoding = Encoding.UTF8; string stringiso = SourceEncoding.GetString(TargetEncoding.GetBytes(s));  Regard Henxon Thank you for your excellent answer. ...

Converting Indy UTF8 Newsgroup Messages to Displayable Unicode
Are there any, or could any kind soul provide, examples of how to get message bodies from TIdNNTP into a form that will display properly on a unicode rich edit control, when the message's encoding is text/plain; charset=UTF8? All the obvious ways have not worked. I'm using the version of Indy that came with D2009, if I remember correctly. Thanks in advance. "John Jacobson" <jake@NOSPAMjsnewsreader.com> wrote in message news:45307@forums.codegear.com... > Are there any, or could any kind soul provide, examples of how > to get message bodies from ...

Web resources about - Converting std::string app to Unicode - use wstring or utf8? - embarcadero.cppbuilder.nontech

Resources last updated: 12/24/2015 5:29:08 PM