I tried the following code which supposed to check if a string contains spaces but I get an error. How else can I check that
if Index('some string',' ')>1 then begin
Result:= False;
end
else begin
Result := True;
end;
You can use pos function. From documentation:
The pos function returns the position of a substring in a main string. If the substring does not exist in the main string, then the returned value will be 0.
s:='note-book';
x:=pos('book',s); {x will be 6}
All this information, and other useful tips you can find here
As an alternative one, AnsiContainsStr can be used for string containing operations.It return True if the string contains the given substring, False otherwise. As an example code:
if AnsiContainStr(mainText, subText) then begin
//enter here if mainText contains subText.
//write code for doing needed operations here
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With