Hi,
I have a std::string which I know is UTF-8 encoded. How can I make a
System::String^ from it?
I tried UTF8Encoding class, but it wants a Byte array, and I don't
know how to get that from a std::string.
Thanks for any help! 4 6161
On Oct 19, 12:43 pm, bar...@bluezone.no wrote:
Hi,
I have a std::string which I know is UTF-8 encoded. How can I make a
System::String^ from it?
I tried UTF8Encoding class, but it wants a Byte array, and I don't
know how to get that from a std::string.
Thanks for any help!
Since you know that your string is UTF-8, you need only be worried
that chars are 8-bits wide.
std::string s = "Hello, World";
char const* buffer = s.c_str();
>From this point you can fill a Byte array. I am not totally sure how
to do this in Managed C++, but it should get you to where you are
going.
Outside of that I can't help you.
<je**********@gmail.comwrote in message
news:11**********************@t8g2000prg.googlegro ups.com...
On Oct 19, 12:43 pm, bar...@bluezone.no wrote:
>Hi,
I have a std::string which I know is UTF-8 encoded. How can I make a System::String^ from it? I tried UTF8Encoding class, but it wants a Byte array, and I don't know how to get that from a std::string.
Thanks for any help!
Since you know that your string is UTF-8, you need only be worried
that chars are 8-bits wide.
std::string s = "Hello, World";
char const* buffer = s.c_str();
>>From this point you can fill a Byte array. I am not totally sure how
to do this in Managed C++, but it should get you to where you are
going.
C++/CLI, not Managed C++
Add these lines to get a Byte array.
cli::array<System::Byte>^ a = gcnew cli::array<System::Byte>(s.length());
int i = s.length();
while (i-- 0)
a[i] = buffer[i];
And then use Encoding::UTF8::GetString(a);
>
Outside of that I can't help you.
<ba****@bluezone.noha scritto nel messaggio
news:11**********************@i13g2000prf.googlegr oups.com...
I have a std::string which I know is UTF-8 encoded. How can I make a
System::String^ from it?
I tried UTF8Encoding class, but it wants a Byte array, and I don't
know how to get that from a std::string.
To add to what others have written, I think that you could also convert the
string from Unicode UTF-8 to Unicode UTF-16 inside C++, using
::MultiByteToWideChar Win32 API.
Then, you can pass the resulting Unicode UTF-16 string value to
System::String (so, in this way you bypass UTF8Encoding class).
Giovanni
On 19 Okt, 22:06, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
<jehugalea...@gmail.comwrote in message
news:11**********************@t8g2000prg.googlegro ups.com...
On Oct 19, 12:43 pm, bar...@bluezone.no wrote:
Hi,
I have a std::string which I know is UTF-8 encoded. How can I make a
System::String^ from it?
I tried UTF8Encoding class, but it wants a Byte array, and I don't
know how to get that from a std::string.
Thanks for any help!
Since you know that your string is UTF-8, you need only be worried
that chars are 8-bits wide.
std::string s = "Hello, World";
char const* buffer = s.c_str();
>From this point you can fill a Byte array. I am not totally sure how
to do this in Managed C++, but it should get you to where you are
going.
C++/CLI, not Managed C++
Add these lines to get a Byte array.
cli::array<System::Byte>^ a = gcnew cli::array<System::Byte>(s.length());
int i = s.length();
while (i-- 0)
a[i] = buffer[i];
And then use Encoding::UTF8::GetString(a);
Outside of that I can't help you.- Skjul sitert tekst -
- Vis sitert tekst -- Skjul sitert tekst -
- Vis sitert tekst -
Thanks, that worked! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brian Reed |
last post by:
I have a class that I want to serialize to an XML string. I want the XML to serialize to utf-8 encoding. When I serialize to an XML file, the data looks great. When I try to serialize to a String...
|
by: Yuriy |
last post by:
Hi,
Can anybody explain the following?
Say I have the following source XML and XSLT (see below). No matter what
this XSLT does. It is just a sample to show a problem. the idea is that
XSLT...
|
by: SDS |
last post by:
Greets,
I am reading some binary data and putting into a System.String object
via Encoding.Default.GetString(). I then take this string and put it
into a dataset field of type System.String.
...
|
by: Jan Eliasen |
last post by:
Hi
I have a string, which I must convert into another string and have it
utf-8 encoded.
My current code looks like this;
Both vDataIn and vDataOut are Objects (parameters to a...
|
by: Ger |
last post by:
I have not been able to find a simple, straight forward Unicode to ASCII
string conversion function in VB.Net.
Is that because such a function does not exists or do I overlook it?
I found...
|
by: Marc |
last post by:
Hi!
I'm working with a C# client that calls a php web service. I've
created a wrapper to call the service using .NET wsdl tool (adding a
web reference).
The call to the server works fine, it...
|
by: Peteroid |
last post by:
These don't work (I'm using VS C++.NET 2005 Express with clr:/pure syntax):
ostream& operator <<( ostream& output, String^ str )
{
output << str ; //compile error
return output ;
}
...
|
by: hg |
last post by:
Hi,
I'm bringing over a thread that's going on on f.c.l.python.
The point was to get rid of french accents from words.
We noticed that len('à') != len('a') and I found the hack below to fix...
|
by: Allan Ebdrup |
last post by:
I hava an ajax web application where i hvae problems with UTF-8 encoding oc
chineese chars.
My Ajax webapplication runs in a HTML page that is UTF-8 Encoded.
I copy and paste some chineese chars...
|
by: Jeffrey Walton |
last post by:
Hi All,
BMP Strings are a subset of Universal Strings.The BMP string uses
approximately 65,000 code points from Universal String encoding. BMP
Strings: ISO/IEC 10646, 2-octet canonical form,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |