472,783 Members | 934 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,783 software developers and data experts.

incorrect result when converting from basic string to System::String

Hi,
I am using a c# library in my c++ project. so I have to convert a
basic string to System::string to make use of a function that takes
System::String as argument. I did it like this:

System::String^ s = gcnew System::String(basic_s.c_str()); //here
basic_s is a basic string in c++

But I found s contains less charactors than the original basic string,
some charactors are missing.
here, the basic string contians bytes that rang from -127 to 127,
which is the result of an encrypting function.

what's wrong with the converting? how to convert the string without
missing charactors?

Thanks!

Vivienne

Aug 20 '07 #1
1 1658
Vivienne <zh**********@gmail.comwrote:
I am using a c# library in my c++ project. so I have to convert a
basic string to System::string to make use of a function that takes
System::String as argument. I did it like this:

System::String^ s = gcnew System::String(basic_s.c_str()); //here
basic_s is a basic string in c++

But I found s contains less charactors than the original basic string,
some charactors are missing.
here, the basic string contians bytes that rang from -127 to 127,
which is the result of an encrypting function.
And what do you expect the result to be? Which encoding to you expect
it to use?

As a general rule, it's a *really, really* bad idea to convert
arbitrary binary data (such as the result of encryption) to text
directly. Use Base64 instead.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 20 '07 #2

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

Similar topics

1
by: Joe | last post by:
I'm trying to convert system.string to a com method that wants a BSTR*, and array of BSTR. Can anyone help?
4
by: Yan Vinogradov | last post by:
There are two ways to convert a char* received from the unmanaged code into a managed System.String object that I am aware of. The first one is to simply construct String object passing char* as...
3
by: Andy Sutorius via DotNetMonster.com | last post by:
Hi, I have a Sorted List that has 9 key/value pairs. I am trying to take one of the key/value pairs and store the value of that key into a string variable. However, the value that actually gets...
2
by: Bae,Hyun-jik | last post by:
Hi, My managed C++ library frequently takes LPCTSTR from managed exe. Due to the fact that my library doesn't modify string buffer if its parameter type is LPCTSTR, it won't be required to copy...
2
by: John Swan | last post by:
Hello. I cannot seem to find any documentation upon the STL string. I am simply trying to transfer the contents of a std::string to a System::String where I am coming into difficulties. Any...
24
by: Marcus Kwok | last post by:
Hello, I am working on cleaning up some code that I inherited and was wondering if there is anything wrong with my function. I am fairly proficient in standard C++ but I am pretty new to the .NET...
6
by: DaTurk | last post by:
Hi, I have several interfaces in CLI that I access via c#. My problem is, is that down in the unmanaged c++, which the CLI lies on top of, I have a lot of c_str() happening. But all of my...
1
by: vcbytes | last post by:
I am having a problem with the following code: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { String^ texts = textBox1->Text; char *text =...
2
by: Man4ish | last post by:
How can we convert std::string into basic string?
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.