473,757 Members | 10,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UnicodeString to std::string or char*

Is there an easy to convert from UnicodeString to string or char *?

Nov 5 '07 #1
3 11666
On Nov 5, 1:37 pm, Travis <travis.bow...@ gmail.comwrote:
Is there an easy to convert from UnicodeString to string or char *?
You mean ICU UnicodeString? You'll need to convert it to UTF-8. See
the ICU converters: http://icu-project.org/userguide/cod...onverters.html

Nov 5 '07 #2
On Nov 5, 2:55 pm, Tristan Wibberley <maihem-...@maihem.orgw rote:
On Mon, 2007-11-05 at 11:04 -0800, Nemanja Trifunovic wrote:
On Nov 5, 1:37 pm, Travis <travis.bow...@ gmail.comwrote:
Is there an easy to convert from UnicodeString to string or char *?
You mean ICU UnicodeString? You'll need to convert it to UTF-8. See
the ICU converters:http://icu-project.org/userguide/cod...onverters.html

Rather than simply UTF-8, you'd be better off converting it to the
character encoding of std::string::va lue_type WRT the std::codecvt facet
of the current global locale (if you expect to do any string processing
or stream it to a std::ostream) or to the std::codecvt facet of the
locale you're going to output the string to if you're going to use some
binary I/O API.
But how you can be sure that all the characters from the UnicodeString
fit into char encoding of the current global locale?

Nov 5 '07 #3

On Mon, 2007-11-05 at 12:41 -0800, Nemanja Trifunovic wrote:
On Nov 5, 2:55 pm, Tristan Wibberley <maihem-...@maihem.orgw rote:
On Mon, 2007-11-05 at 11:04 -0800, Nemanja Trifunovic wrote:
On Nov 5, 1:37 pm, Travis <travis.bow...@ gmail.comwrote:
Is there an easy to convert from UnicodeString to string or char *?
You mean ICU UnicodeString? You'll need to convert it to UTF-8. See
the ICU converters:http://icu-project.org/userguide/cod...onverters.html
Rather than simply UTF-8, you'd be better off converting it to the
character encoding of std::string::va lue_type WRT the std::codecvt facet
of the current global locale (if you expect to do any string processing
or stream it to a std::ostream) or to the std::codecvt facet of the
locale you're going to output the string to if you're going to use some
binary I/O API.

But how you can be sure that all the characters from the UnicodeString
fit into char encoding of the current global locale?
You can set the global locale to have a UTF-8 char codecvt facet, or you
can decline to use any string processing functions unless you can pass a
locale/codecvt facet that tells it that the string is UTF-8 and decline to
stream the string through a std::ostream (although you can .imbue() the stream
with an appropriate locale).

Although, if you are just going to throw the data out to a file via binary I/O
or if you will have custom UTF-8 processing functions then you can do it safely.

I'm kind of just trying to warn against throwing character sets and encodings
around just because it seems like they fit better in a particular data type
(UTF-16 can be put into a std::string too).

--
Tristan Wibberley

Any opinion expressed is mine (or else I'm playing devils advocate for
the sake of a good argument). My employer had nothing to do with this
communication.

Nov 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
22736
by: Espen Ruud Schultz | last post by:
Lets say I have a char pointer and an std::string. Is it possible to get a pointer to the std::string's "content" so that the char pointer can point to the same text? And vice versa; can I give the std::string a pointer and a length and then give the std::string control over the pointer and its content? I'm basically trying to avoid copying large text between an std::string and a char pointer, and vice versa. Is there anyhing in the...
24
11029
by: Julie | last post by:
I'm re-evaluating the way that I convert from a std::string to char *. (Requirement: the source is a std::string, the usable contents are char *) Here is what I've come up with: #include <string> #include <vector> #include <cstring> // presume s from somewhere, such as:
16
16426
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
6
6642
by: Khuong Dinh Pham | last post by:
How do i read the contents of a xml file and output it to a std::string. Thx in advance
8
4814
by: Jason Heyes | last post by:
If s is a std::string, does &s refer to the contiguous block of characters representing s?
37
3806
by: jortizclaver | last post by:
Hi, I'm about to develop a new framework for my corporative applications and my first decision point is what kind of strings to use: std::string or classical C char*. Performance in my system is quite importante - it's not a realtime system, but almost - and I concern about std::string performance in terms of speed. No doubt to use std implementation is a lot easier but I can't sacrifice speed.
10
26635
by: sposes | last post by:
Im very much a newbie but perhaps somehone can help me. Ive been searching for a way to convert a std::string to a unsigned char* The situation is I have a function that wants a unsigned char* and I want to give it a std::string no matching function for call to `MD5::update(std::string&, size_t)' candidates are: void MD5::update(unsigned char*, unsigned int) void PrintMD5(string str){
6
4859
by: SteelSide | last post by:
Ive searched and searched,but havent been able to get it to work. ----------------- #include <iostream> using namespace std; std::string tempHostNameStr = "s1e2.hidden.thingy.org"; char szHostName;
13
3670
by: arnuld | last post by:
/* C++ Primer 4/e * section 3.2 - String Standard Library * exercise 3.10 * STATEMENT * write a programme to strip the punctation from the string. */ #include <iostream> #include <string>
0
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7286
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.