Board index » delphi » string --> array of char

string --> array of char

Hi,

Quote
Robert J.N. Speirs wrote:
> How do I convert a string to an array of char?

Loosely speaking, a string *is* an array of char.

Quote
> var
>   fileString:string;
> begin
>   readln(fileString);
>   write(fExpand(fileString));

> .. but I want to print the string to the screen in lowercase characters.

   function lowstr(s : string) : string;
   var i : integer;
   begin
      for i := 1 to length(s) do if s[i] in ['A'..'Z'] then
         s[i] := chr(ord(s[i]) or $20);
      lowstr := s;
   end;

But note that this simple routine doesn't convert ? to ?, for example.

 - Sebastian

--
function HasAttachment : Boolean;
begin  { Does a posting have an attachment? }
   HasAttachment := Random(2) = 1;
end

 

Re:string --> array of char


Robert J.N. Speirs wrote ...
Quote
>How do I convert a string to an array of char?

>For example I have...

>var
>  fileString:string;
>begin
>  readln(fileString);
>  write(fExpand(fileString));

>.. but I want to print the string to the screen in lowercase

characters.

A string IS an array of char.  In your case fileString[0] contains a
length byte of the string and items
fileString[1]..fileString[length(fileString)] are the characters of
the string as char.

In Borland Pascal compilers there is not any LowCase function, only
UpCase for one char, so you have to write your own function.

--
Raimo Suonio, Helsinki, Finland
http://www.dlc.fi/%7Eexp-1/suonio/
Oikeinkirjoitusohjeita news- ja web-kirjoittajille:
http://www.dlc.fi/%7Eexp-1/oikeinkirjoitus.html

Re:string --> array of char


In article <8hmq64$se...@tron.sci.fi>,
  "Raimo Suonio" <raimo.suo...@dlc.fi> wrote:

Quote
> A string IS an array of char.

A few times I've used for example "string[5] absolute xxxx:xxxx"
and "array[1..5] of char absolute xxxx:xxxx" and both have given
different results.

--
Iain Jones         xh0u9...@NOSPAMliv.ac.uk
Faculty Of Science, University Of Liverpool
http://www.liv.ac.uk

Sent via Deja.com http://www.deja.com/
Before you buy.

Re:string --> array of char


In article <8ho6i9$si...@nnrp1.deja.com>,
Iain Jones  <i_p_jo...@my-deja.com> wrote:

Quote
>In article <8hmq64$se...@tron.sci.fi>,
>  "Raimo Suonio" <raimo.suo...@dlc.fi> wrote:
>> A string IS an array of char.

>A few times I've used for example "string[5] absolute xxxx:xxxx"
>and "array[1..5] of char absolute xxxx:xxxx" and both have given
>different results.

String has the length byte as first byte. Also you should not mess with
absolutes, you can cause havoc with them.

Osmo

Re:string --> array of char


Iain Jones kirjoitti viestiss? <8ho6i9$si...@nnrp1.deja.com>...

Quote

>A few times I've used for example "string[5] absolute xxxx:xxxx"
>and "array[1..5] of char absolute xxxx:xxxx" and both have given
>different results.

Yes, because string[5] and array[1..5] are not equal definitions.  The
correct counterpart for string[5] is array[0..5].  They are not
totally equal because you can't use the array in string expressions
and it won't keep the zeroth element updated as a length byte.  But
they are of equal size, six bytes, and you can handle string[5] as it
was defined as array[0..5].  And you don't even have to use any double
definitions to do that, the possibility is available at any time.

--
Raimo Suonio, Helsinki, Finland
http://www.dlc.fi/%7Eexp-1/suonio/
Oikeinkirjoitusohjeita news- ja web-kirjoittajille:
http://www.dlc.fi/%7Eexp-1/oikeinkirjoitus.html

Re:string --> array of char


Quote
Osmo wrote:
>you should not mess with
>absolutes, you can cause havoc with them.

never say never.

your statement as it stands is too broad.

absolutes have their place in DOS real-mode
programming.

Re:string --> array of char


In article <8hpaca$...@journal.concentric.net>,
Dr. Juan Stockman <DrJ...@merlyn.edu> wrote:

Quote

>Osmo wrote:

>>you should not mess with
>>absolutes, you can cause havoc with them.

>never say never.

>your statement as it stands is too broad.

>absolutes have their place in DOS real-mode
>programming.

True, but still one should not _mess_ with them.

Osmo

Other Threads