View Full Version : String searching
Voltrox
19-12-2006, 07:11 PM
Hello.
How do I search for a keyword in a string?
Like...
variable1 := 'How do I check to see if Voltrox is contained in this string?';
Then search variable1 to determine if it contains Voltrox.
JernejL
19-12-2006, 07:18 PM
use function "pos"
Voltrox
19-12-2006, 07:42 PM
How do I use pos?
I see substring and wide string when i type it.
But I don't know how to use it.
JernejL
19-12-2006, 07:48 PM
How do I use pos?
I see substring and wide string when i type it.
But I don't know how to use it.
use delphi help perhaps?!?
Pos returns the index value of the first character in a specified substring that occurs in a given string.
Unit
System
Category
string handling routines
function Pos(Substr: string; S: string): Integer;
Description
Pos searches for a substring, Substr, in a string, S. Substr and S are string-type expressions.
Pos searches for Substr within S and returns an integer value that is the index of the first character of Substr within S. Pos ignores case-insensitive matches. If Substr is not found, Pos returns zero.
NecroDOME
19-12-2006, 07:48 PM
type Pos and pres F1:
Returns the index value of the first character in a specified substring that occurs in a given string.
Unit
System
Syntax
[Delphi] function Pos(const substr: string; const str: string): Integer; overload;
[Delphi] function Pos(const substr: WideString; const str: WideString): Integer; overload;
Description
In Delphi, Pos searches for a substring, Substr, in a string, S. Substr and S are string-type expressions.
Pos searches for Substr within S and returns an integer value that is the index of the first character of Substr within S. Pos is case-sensitive. If Substr is not found, Pos returns zero.
EDIT: @Delfi, LOL
Voltrox
19-12-2006, 07:51 PM
Oh. So how do I get the index that's the end of the string?
Is there a way to do a thing called IF the string is found in the variable then execute my code?
Setharian
19-12-2006, 08:39 PM
well maybe by using simple math? :)
increment that returned index from Pos by the length of the string searched....and yes, you can branch your code depending on that...if you're just interested if the string is present, use Pos and check the result <> 0...if it is non-zero, the substring has been found....
Voltrox
19-12-2006, 08:52 PM
Ok. Thank you. :)
I'll do that.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.