BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

StringToCharArrayToByteArray

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General)
View previous topic :: View next topic  
Author Message
Carl Motsinger
Guest





PostPosted: Fri May 19, 2006 5:14 am    Post subject: StringToCharArrayToByteArray Reply with quote



Is there something in Delphi7 to:

Take the letters in a string , for example..."XXX"

....place them into Char Array then

another something?... and place

that into a Byte array?

Or just convert "XXX" into a 3 element Byte array.

Carl Motsinger
Back to top
Justus J.
Guest





PostPosted: Sat May 20, 2006 12:14 pm    Post subject: Re: StringToCharArrayToByteArray Reply with quote



Hi,

what's the need for this? Characters in a string can be identified using
the index, which in turn can be typecasted to bytes:

s := 'hello world';
c := s[5]; // o
b := byte(c); // 111 or b := ord(c);

or, shorter :

b := byte(s[5]);

Justus



can On 19/05/2006 06:18, Carl Motsinger wrote:
Quote:
Is there something in Delphi7 to:

Take the letters in a string , for example..."XXX"

....place them into Char Array then

another something?... and place

that into a Byte array?

Or just convert "XXX" into a 3 element Byte array.

Carl Motsinger

Back to top
Riki Wiki
Guest





PostPosted: Sat May 20, 2006 2:14 pm    Post subject: Re: StringToCharArrayToByteArray Reply with quote



On Thu, 18 May 2006 23:18:58 -0500, Carl Motsinger wrote:

Quote:
Or just convert "XXX" into a 3 element Byte array.

Hoi Carl

You can use StrPCopy for that. It copies from string to a C style
null-terminated pointer string. Use StrPLCopy to check for overflow of
receving array.

uses SysUtils;
var
arr: array[0..9] of Char;
s: String;
....
s:='abc';
StrPCopy(arr,s);

If you actually only need the string as a parameter to call C style API
(Win32) you can just type cast the Delphi string, use pchar. Note: If the
Delphi string should receive string data back (var reference) from such a
call you need to assure enough space has been allocated, to do so use
SetLength.

Beside this, you need to be aware that this news group do not officially
exist. For further questions about your problem post in
b.p.d.language.delphi.general, and when you do so you need to post on the
Borland news server.

<http://tinyurl.com/8m5nw>
which links to
<http://delphi.wikicities.com/wiki/Delphi_Newsgroups>
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.