string --> array of char 
Author Message
 string --> array of char

Hi,

Quote:

> 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



Wed, 18 Jun 1902 08:00:00 GMT  
 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



Wed, 18 Jun 1902 08:00:00 GMT  
 string --> array of char


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.

--

Faculty Of Science, University Of Liverpool
http://www.liv.ac.uk

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



Wed, 18 Jun 1902 08:00:00 GMT  
 string --> array of char


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.

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

Osmo



Wed, 18 Jun 1902 08:00:00 GMT  
 string --> array of char

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



Wed, 18 Jun 1902 08:00:00 GMT  
 string --> array of char

Quote:

>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.



Wed, 18 Jun 1902 08:00:00 GMT  
 string --> array of char


Quote:


>>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



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Array of Char -> String

2. Array of Strings and Char?

3. TP7: Converting String to Array of Char

4. convert string to array of char?

5. char array output as string?

6. String to Array of Char Conversion

7. Weird char>string conversion

8. integer ----> char/string

9. String ---> Char

10. String manipulation > 255 chars

11. String->Char

12. char/string -> integer

 

 
Powered by phpBB® Forum Software