Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Tai-Pan

AnsiString conversion

This topic is 5710 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Ive started to use Builder C++ from Borland v4. The problem is that I need some way to convert a standard C++ string to a Borland AnsiString, is that possible? Ive searched the complete help database that comes with Builder, but I cant find anything...I think Im screwed. Thanks

Share this post


Link to post
Share on other sites
Advertisement
AnsiString should have a char *-taking constructor, and you can get a c-style string from std::string by using c_str().

Share this post


Link to post
Share on other sites
Thanks for answering, but I think you didnt understand which is my problem, or maybe I didnt understand you
I have an Edit Box (which are used to input text), but Edit boxes store their text only as AnsiStrings. I also have an object with a string member, and it can only be a string, I cant change that, well, I need to convert the information contained in the EditBox (AnsiString) and store it in my String variable, is that possible?

Share this post


Link to post
Share on other sites
I just read my original question...I made a mistake, I said that I had to convert a String to a AnsiString, but as I said on my previous post, I need to convert an AnsiString to String. Sorry for the confution.

Share this post


Link to post
Share on other sites
As niyaw said use the c_str() function. An AnsiString is stored internally as a null terminated array of char and c_str() returns a pointer to that array. One caveat though is you have to copy the string into your object and not just store the pointer. AnsiString is copy on modify. That means anytime you modify the string a new array is created to hold the result. They are also referance counted so multiple strings can be using the same array and the old array will only be deleted if you are the last one using it.

Share this post


Link to post
Share on other sites
converting ansistring to string: tried this?

AnsiString blah;
string bleh(blah);

if that doesn''t work, then look for a member function of ansistring that returns a c-style string (const char *).

Share this post


Link to post
Share on other sites
Thanks people..im gonna try that as sonn as I reinstall the compiler..it started to behave like sh$% with any reason.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!