字符串转成字符(30分)

  • 主题发起人 主题发起人 lbylby
  • 开始时间 开始时间
L

lbylby

Unregistered / Unconfirmed
GUEST, unregistred user!
有没有把字符串类型转成字符类型的方法?
 
MyString.c_char()
 
string就是字符
 
同意silverwolf
定义char * 或char形数组然后如 silverwolf 所写赋值
 
char(ansistring());
 
string,表示字符串的第i個字符
eg:
var
a:string;
begin
a:='abcde';
a[2] 就是 'b'

 
我想是这样吧!!!
朋友们可测试一下代码!!!
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString MyString;
MyString=Edit1->Text;
Edit2->Text=MyString.c_str();
String str="My love will go on!!!";
char *str1=str.c_str();
//char* __fastcall c_str() const;
Edit3->Text=str1;
}
下面是我在BCB中找到的帮助:
char* __fastcall c_str() const;
AnsiString c_str() example
AnsiString::c_str() returns a non const temporary pointer to the internal string buffer in the AnsiString object. The pointer is invalid once the statement in which it is used has finished executing. That is,don'tdo
something like this:
char* cp = Edit1->Text.c_str();
char* cp2 = strtok( cp, " /t/n" );
// cp may no longer be valid

If you need a persistent pointer, you MUST copy the string into its own buffer:
char* cp = new char[ Edit1->Text.Length() + 1 ];
strcpy( cp, Edit1->Text.c_str() );
 
多人接受答案了。
 
后退
顶部