Board index » delphi » TP7: Converting String to Array of Char

TP7: Converting String to Array of Char

Hello everybody

Hov to do $subject the right way?

regards S?ren Schimkat

 

Re:TP7: Converting String to Array of Char


Dirty trick:
var s:string;
var c:array[0..255] of char absolute s;
var l:byte absolute s;

It means you have a "s" string as a varible. You also have a "c" array of
bytes that is on the same place. It works, as string is simply a character
array, with the lenght in the 0. byte. This why "c" starts from 0. And we
also have an "l" byte on the same place (s[0]=c[0]=l) that means the
length of the string.

So if you do this, you get the lenght of the string in l, and c[1] is 1st
char of the string, c[255] is 255th char of the string.

BUT we don't write your homework here instead of you. SO i guess if it was
a homework, your teacher wouldn't accept this particular solution.

If it wans't a homework, but you needed it for your proggie, it will work
under tp6.0, tp7.0 and bp7.0.

bye

Igor2
----------
Igor2@ircnet (irc.stealth.net:6668 chat.bt.net:6679) #dos, #irc, #pascal
*.hu accounts for rent (for an eggdrop)

Quote
On Mon, 19 Feb 2001, Soren Schimkat wrote:
> Hello everybody

> Hov to do $subject the right way?

> regards S?ren Schimkat

Re:TP7: Converting String to Array of Char


Quote
In article <3A9111C0.6B614...@musik.auc.dk>, Soren Schimkat wrote:
>Hello everybody

>Hov to do $subject the right way?

Depends on how what you think an array of char is.

- Should it be null terminated?
- padded with spaces or other char to maximal length?
- can you allow the maximal length to be 254 not 255?

Re:TP7: Converting String to Array of Char


Hi Marco

Marco van de Voort wrote:

Quote

> In article <3A9111C0.6B614...@musik.auc.dk>, Soren Schimkat wrote:
> >Hello everybody

> >Hov to do $subject the right way?

> Depends on how what you think an array of char is.

> - Should it be null terminated?

No.

Quote
> - padded with spaces or other char to maximal length?

No.

Quote
> - can you allow the maximal length to be 254 not 255?

yes.

I believe that I has got the information i need (see the message from
Igor) - but if you has another way of writing the code then let us see
it. :-)

Regards S?ren

Re:TP7: Converting String to Array of Char


Quote
In article <3A9125A4.5C525...@musik.auc.dk>, Soren Schimkat wrote:
>Hi Marco

>Marco van de Voort wrote:

>> In article <3A9111C0.6B614...@musik.auc.dk>, Soren Schimkat wrote:
>> >Hello everybody

>> >Hov to do $subject the right way?

>> Depends on how what you think an array of char is.

>> - Should it be null terminated?

>No.

>> - padded with spaces or other char to maximal length?

>No.

>> - can you allow the maximal length to be 254 not 255?

>yes.

>I believe that I has got the information i need (see the message from
>Igor) - but if you has another way of writing the code then let us see
>it. :-)

Then it is ok. But of course you can access a string as "array of char"
directly, only that you have a length byte prefixed.

Re:TP7: Converting String to Array of Char


On Mon, 19 Feb 2001 13:54:48 GMT, Soren Schimkat

Quote
<schim...@musik.auc.dk> wrote:
>Hi Marco

>Marco van de Voort wrote:

>> In article <3A9111C0.6B614...@musik.auc.dk>, Soren Schimkat wrote:
>> >Hello everybody

>> >Hov to do $subject the right way?

>> Depends on how what you think an array of char is.

>> - Should it be null terminated?

>No.

>> - padded with spaces or other char to maximal length?

>No.

>> - can you allow the maximal length to be 254 not 255?

>yes.

>I believe that I has got the information i need (see the message from
>Igor) - but if you has another way of writing the code then let us see
>it. :-)

For many purposes a Borlandish Pascal string can be treated very much
like an array of characters (i.e. you can iterate it like an array,
you can access the idividual elements (chars) using array notation).

Given that you don't need null termination or padding, then you may
not need to perform any conversion at all.

If you can provide some more details on what it is you need to do,
that will be easier to determine.

Stephen Posey
slpo...@concentric.net

Other Threads