Ian Branch 127 Posted February 11, 2022 Hi Team, I need to be able to detect and return true or false, if an integer number is in a delimited string of numbers.. i.e. If the integer is say 47, and the delimited number string is '12;94;128;3;127,147', then it would return False. If the integer is say 47, and the delimited number string is '12;94;128;3;127,47', then it would return True. If the integer is say 47, and the delimited number string is '12;147;128;3;127,47', then it would return True. Your thoughts/suggestions appreciated. Regards & TIA, Ian Share this post Link to post
Lajos Juhász 293 Posted February 11, 2022 Is the list correct in your example the first numbers are delimited with semicolon while the last is with comma. The easiest way to type this for me is: function ListContains(const PList: string; PNumber: integer): boolean; var sl: TStringList; begin sl:=TStringList.Create; try sl.Delimiter:=';'; sl.DelimitedText:=StringReplace(PList, ',', ';', []); result:=sl.IndexOf(IntToStr(PNumber))<>-1; finally sl.Free; end; end; Share this post Link to post
Ian Branch 127 Posted February 11, 2022 Hi Lajos, 7 minutes ago, Lajos Juhász said: Is the list correct in your example Interdigital Interface Difficulties. a.k.a. Finger Fault - It should be ; :-( Thank you for the code, I will have at it. Regards, Ian Share this post Link to post
Uwe Raabe 2057 Posted February 11, 2022 If you make use of some newer features of the RTL you can also write: uses System.SysUtils, System.StrUtils; function ListContains(const PList: string; PNumber: integer): boolean; begin Result := MatchStr(PNumber.ToString, PList.Split([';', ','])); end; An advantage is the simple support for additional separators. Share this post Link to post
0x8000FFFF 22 Posted February 11, 2022 \b47\b https://regex101.com/r/FhA9Hx/1 Share this post Link to post
Attila Kovacs 629 Posted February 11, 2022 (edited) You did not specify any problems, so these are coming to my mind right now. Edited February 11, 2022 by Attila Kovacs Share this post Link to post
Ian Branch 127 Posted February 11, 2022 Hi Team, Thank you for your further suggestions. I am now going with Uwe's suggestion. Uwe - I like simple. 0x9000FFFF - regular expressions scare me, like pointers... ;-) Atilla - Thank you for the pointers. Regards & Tks again, Ian Share this post Link to post