[HELP] Finding whole words in a string? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [HELP] Finding whole words in a string? (
/showthread.php?tid=139215)
[HELP] Finding whole words in a string? -
Ibanez - 04.04.2010
Hey, I need some help... Is there any way on finding a
whole word in a string? example: If i wanted to find the word "Brock".
Would find the word Brock.
Code:
My name is Brockaleana
Would not find the word Brock.
If anyone could help me with this it would be much appreciated!
Re: [HELP] Finding whole words in a string? -
Jefff - 04.04.2010
Code:
if(strfind(string,"Brock",true)!=-1) {
print("Got ya");
}
Re: [HELP] Finding whole words in a string? -
Ibanez - 04.04.2010
Quote:
Originally Posted by Jefff
Code:
if(strfind(string,"Brock",true)!=-1) {
print("Got ya");
}
|
Still doesn't do what I wanted it to do
I want it to find it like this:
My name is
Brock = Found
My name is
Brockaleana = Not Found
Re: [HELP] Finding whole words in a string? - WackoX - 04.04.2010
Use the explode or split function by Denver, and split on space.
Re: [HELP] Finding whole words in a string? -
Ibanez - 04.04.2010
Quote:
Originally Posted by WackoX
Use the explode or split function by Denver, and split on space.
|
Thank's, i'll take a look and see if i can get it working
Re: [HELP] Finding whole words in a string? -
Beaver07 - 04.04.2010
put this under OnPlayerText(playerid, text[])
Code:
new str[128];
format(str, 128, "%s", text);
new start;
for(new letter; letter<strlen(str); letter++)
{
start = strfind(str, "Word", true); //Checking if word from list can be found in the message
if(start != -1) //If The word is found
{
if(letter == start)
{
// Do Something here
return 1; // return 0; if you dont want the text to be shown.
}
}
}
i used this code as my swear filter i hope you can use this for what you need it.
Re: [HELP] Finding whole words in a string? -
Dabombber - 04.04.2010
pawn Code:
/**
* Finds a word in a string
* @param string The string to search
* @param word The word to search for
* @param ignorecase If the search is case insensitive
* @param pos The starting position for the search
* @return The position in the string of the begining of the word, or -1 if not found
*/
stock strfindword(const string[], const word[], bool:ignorecase=false, pos=0)
{
if(isnull(word)) return -1;
new wlen = strlen(word);
if(ispacked(string)) {
for(new i = strfind(string, word, ignorecase, pos); i != -1; i = strfind(string, word, ignorecase, ++i)) {
if((i == 0 || string{i-1} <= ' ') && string{i+wlen} <= ' ') {
return i;
}
}
} else {
for(new i = strfind(string, word, ignorecase, pos); i != -1; i = strfind(string, word, ignorecase, ++i)) {
if((i == 0 || string[i-1] <= ' ') && string[i+wlen] <= ' ') {
return i;
}
}
}
return -1;
}