Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to convert AnsiString to unsigned char ?

564 views
Skip to first unread message

Maxim Andreev

unread,
May 19, 2001, 1:25:28 PM5/19/01
to
How to convert AnsiString to unsigned char ?

JDS

unread,
May 19, 2001, 2:51:56 PM5/19/01
to
How, indeed? How to convert an array of integers into an integer? How to
convert a poem into the letter 'e'? How to convert a river into a molecule
of water? There's no objective, general basis upon which to answer these
deep, philosphical questions.

If, rather, you mean how do you convert an AnsiString to a null-terminated
array of unsigned char, use the c_str() member function. It returns a const
unsigned char* to the underlying character array.

"Maxim Andreev" <fa...@aiocaz.com> wrote in message news:3b06ad6c_2@dnews...

Rudy Velthuis (TeamB)

unread,
May 19, 2001, 5:25:11 PM5/19/01
to
In article <3b06ad6c_2@dnews>, Maxim Andreev says...

> How to convert AnsiString to unsigned char ?

AnsiString A = "Hello";
char *s = new char[A.Length() + 1];

strcpy(s, A.c_str());

etc...

--
Rudy Velthuis (TeamB)

Rudy Velthuis (TeamB)

unread,
May 19, 2001, 5:41:36 PM5/19/01
to
In article <MPG.157103242...@newsgroups.borland.com>, Rudy
Velthuis (TeamB) says...

> In article <3b06ad6c_2@dnews>, Maxim Andreev says...
>
> > How to convert AnsiString to unsigned char ?
>
> AnsiString A = "Hello";
> char *s = new char[A.Length() + 1];
>
> strcpy(s, A.c_str());

I should learn to read. You want an array of unsigned char?
--
Rudy Velthuis (TeamB)

Maxim Andreev

unread,
May 20, 2001, 5:35:38 AM5/20/01
to

I need to pass text from TMemo to NetMessageBufferSend function as "buf"
parameter.
The value TMemo is AnsiString. But function requires unsigned char.


Ted Byers

unread,
May 20, 2001, 7:25:54 AM5/20/01
to
>
> I need to pass text from TMemo to NetMessageBufferSend function as "buf"
> parameter.
> The value TMemo is AnsiString. But function requires unsigned char.
>
That is what AnsiString (and std::string for that matter) has c_str() for.
If you have a function foo with the following signature:

bool foo(char*);

And an AnsiString 'bar', you can pass bar to foo as follows:

foo(bar.c_str();

HTH

Ted

R.E. Byers
ted....@sympatico.ca

x

unread,
May 21, 2001, 4:53:02 AM5/21/01
to
Try:

char work[100];
String str;
strcpy(work,str.c_str());

"Maxim Andreev" <fa...@aiocaz.com> wrote in message news:3b06ad6c_2@dnews...

Jeffrey Slavin

unread,
May 21, 2001, 5:38:16 AM5/21/01
to
this is what you are looking for
whenever you are trying to pass a AnsiString to a function and the function
calls for a
const char *, or a char * then instead of just passing the AnsiString pass

AnsiString.c_str();

example:

AnsiString myString = TMemo->Text;
CallThisFunction(myString.c_str());

and that's it.
hope this helps

slavin

"x" <1_i...@msn.com> wrote in message news:3b08d731_1@dnews...

0 new messages