Board index » cppbuilder » string to AnsiString and AnsiString to string

string to AnsiString and AnsiString to string


2003-10-14 08:10:50 AM
cppbuilder26
how do i make a normal string from the standard c string library work with
AnsiString which is from vcl.h in c++ builder ?
how do i make a normal string from the standard c string library work with
AnsiString which is from vcl.h in c++ builder ?
 
 

Re:string to AnsiString and AnsiString to string

On Tue, 14 Oct 2003 01:10:50 +0100, <abbas>wrote:
Quote
how do i make a normal string from the standard c string library work with
AnsiString which is from vcl.h in c++ builder ?
how do i make a normal string from the standard c string library work with
AnsiString which is from vcl.h in c++ builder ?
AnsiString has a c_str() method which gives you a pointer to the
underlying char * data.
AnsiString also has a constructor that takes char *
Thus you can do this:
char * thing = "Something";
AnsiString AS = thing;
printf("%s", AS.c_str());
etc.
--
liz
 

Re:string to AnsiString and AnsiString to string

On Tue, 14 Oct 2003 01:10:50 +0100, <abbas>wrote:
Quote
how do i make a normal string from the standard c string library work with
AnsiString which is from vcl.h in c++ builder ?
how do i make a normal string from the standard c string library work with
AnsiString which is from vcl.h in c++ builder ?
For std::string you do something like:
std::string ss;
AnsiString AS;
AS = "thing";
ss = AS.c_str();
When using something like a TEdit, you do this:
AnsiString AS = Edit1->Text;
// Manipulate AS
then
Edit1->Text = AS;
--
liz
 

{smallsort}

Re:string to AnsiString and AnsiString to string

<abbas>wrote in message news:3f8b3f0a$ XXXX@XXXXX.COM ...
Quote
how do i make a normal string from the standard c string
library work with AnsiString which is from vcl.h in c++ builder ?
Assuming you are referring to the std::string class, then both std::string
and AnsiString have a c_str() method and both have a char* constructor. So
you can do the following:
std::string s1 = "something";
AnsiString s2 = s1.c_str();
std::string s3 = s2.c_str();
Gambit