Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting AnsiString to Char......

Status
Not open for further replies.

LoneRanger123

Programmer
Dec 19, 2000
62
GB
there has got to be a function to do this....

I need a char pointer, and i need to make the string from my own "String of Text" and TEdit->Text property.

Any thoughts? :)
 
Is there any Site with lots of Info on AnsiStings, like if there are Char Functions to say... search for a character in a string
and stuff liek that, showing the String Equivilents?
 
Take a look the c_str() method. For example,
Code:
AnsiString AString = "A String";
char cString[50];
cString = AString.c_str();

BTW, c_str() is a C++ keyword. There was an excellent article in July and August 1997 Builder's Developer Journal. You have to have a subscription to their magazine to see the back issues. See for more info. James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
With that it says LValue Required on the line

cString = AString.c_str();

 
Urk, that's what I get when I give advice when I'm tired. You cannot assign character arrays with the = sign. Use something like strcpy.
James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
Those code doesnt run, because in the c_string, the asign doesnt copy the string, only point to the fist character of the memory that have the string. YOU MUST USE THE strcpy(), of the string library <string.h>.
The correct mode is:
AnsiString AString = &quot;A String&quot;;
char cString[50];
strcpi(cString,AString.c_str());
 
Like this:

char *ptr_new = new char[Text.Length()+1];
strcpy(ptr_new, Text.c_str());

you should declare Text to be AnsiString.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top