0 0 Votes

Delphi/Lazarus: Convert String to Char

Question by Guest | 02/01/2018 at 08:44

I have a string that I would like to convert to a char, because I can only pass it to a function like that.

Although my string only consists of a single letter, which actually corresponds to a char, the function does not accept my input. Is there any way to change the string to a variable of type Char? Something like c := s ist not possible.

ReplyPositiveNegative

Delphian

Show Profile | Message
Avatar
0Best Answer
0 Votes

Similar to an array, you can also access the individual parts of a string.

So for example:

var
  c: char;
  s: string;
begin
  s := 'A';
  c := s[1];  
end;

Here you have a string with the content "A", which we convert to a char with the content "A".

With s[i] you get the letter at the corresponding position i of s. s[1] would be the first letter of s, because unlike an array, the counting does not begin at 0 but starts with 1.
02/01/2018 at 19:49

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own articles on askingbox.com. How to do.