if-statementpascal

Checking for character in a string


I need to check a string, in this case called "word," to see if it contains a letter (or character if you prefer). I don't really need to know the location of the letter, simply if it is present. Currently I have this:

if character in word then //both "word" and "character" are string variables.
begin
{some code}
end;

Trouble is, is that this is just me ripping off a python function:

if character in word: //In python I would use an array for "word" 
    //some code

And this doesn't seem to work in pascal.

This may seem like a dumb question, but I am very new to pascal and indeed to asking for help on stack exchange. Any help as to how to check for characters in strings would be greatly appreciated.


Solution

  •   if pos(character,word)>0 then
         ... some code
    

    pos is overloaded for both characters and strings (for substring matches)

    Note that searching is case sensitive. Uppercase() both character and word if you want otherwise.