Anyone can help with how can I find the first full Word that contains numbers? I have an adress, for example:
procedure TForm1.Button4Click(Sender: TObject);
var
To avoid splitting the string in words:
function ExtractFirstWordWithNumber(const SourceString: String): String;
var
i,start,stop: Integer;
begin
for i := 1 to Length(SourceString) do
begin
if TCharacter.IsDigit(SourceString[i]) then
begin // a digit is found, now get start location of word
start := i;
while (start > 1) and
(not TCharacter.IsWhiteSpace(SourceString[start-1])) do
Dec(start);
// locate stop position of word
stop := i;
while (stop < Length(SourceString)) and
(not TCharacter.IsWhiteSpace(SourceString[stop+1])) do
Inc(stop);
// Finally extract the word with a number
Exit(Copy(SourceString,start,stop-start+1));
end;
end;
Result := '';
end;
First locate a digit, then extract the word from the digit position.