[SOLVED]Check if char exists in a predefined array lazarus / 62-General ---------------------------------------------------------------------- torbente · 2021-01-11 18:25 Using Lazarus 2.0.10, on win 8.1 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Const:MyArray : array[0..3] of char = ('A','N','S','O'); s : string = 'LWFEUÑOWWÑLKDWE';for counter := 1 to length(s) do   // if s[counter] exist in MyArray do something How i can check i s[counter] is valid char in myarray? i could add another counter to check if s[counter] = MyArray[counter2], but i want know if there is a simple way to do it. Thanks. ---------------------------------------------------------------------- Bart · 2021-01-11 18:30 IIRC then fpc trunk allows the "in" operator for that (which internally will I think use a loop. If you make MyArray a string then you can use Pos() to determine if a char is in MyArray. Internally this uses more optimized code than a simple for loop IIRC, so it might be faster. Bart ---------------------------------------------------------------------- ASerge · 2021-01-11 19:56 You can also use sets if the array does not contain "long" characters. And I would recommend write a separate CharInArray function, and then choosing it implementation. ---------------------------------------------------------------------- torbente · 2021-01-11 20:36 Thanks for the replys: The pos function using a string is a great solution! ---------------------------------------------------------------------- Zvoni · 2021-01-12 07:21 The way i do it: Loop through MyArray (instead of your target-string) and use StrScan https://www.freepascal.org/docs-html/current/rtl/strings/strscan.html ---------------------------------------------------------------------- PascalDragon · 2021-01-12 07:53 Quote from: Zvoni on January 12, 2021, 08:21:41 amThe way i do it: Loop through MyArray (instead of your target-string) and use StrScan https://www.freepascal.org/docs-html/current/rtl/strings/strscan.html Better use Pos. Pascal strings are allowed to have NUL characters, while StrScan works on NUL-terminated strings, thus will stop on the first NUL found. ---------------------------------------------------------------------- Zvoni · 2021-01-12 08:48 Quote from: PascalDragon on January 12, 2021, 08:53:42 amQuote from: Zvoni on January 12, 2021, 08:21:41 amThe way i do it: Loop through MyArray (instead of your target-string) and use StrScan https://www.freepascal.org/docs-html/current/rtl/strings/strscan.html Better use Pos. Pascal strings are allowed to have NUL characters, while StrScan works on NUL-terminated strings, thus will stop on the first NUL found. PD, i know that. That's why i wrote "The way i do it", since i have full control of "my" strings.....