Get the next word in a string?
#4

pawn Код:
printf( "%s", strnext("Name: John - Color: Orange - Age: 29 - IP: 127.0.0.1", "Color:", "-") );

stock strnext( const source[], sub[], endchar[] )
{
    new result[32], strt, endstr, len = strlen(source);
    strt = strfind(source, sub, false)+strlen(sub)+1;
    endstr = strfind(source, endchar, true, strt+strlen(sub));
    if(!strlen(endchar)) { strmid(result,source,strt,len); }
    else { strmid(result,source,strt,endstr); }
    return result;
}

//Other Example:
new string[] = "Name: Evil Man || Suspect: Drama Queen || Location: Notting Hills || Combat: Ninja";
   
printf( "%s", strnext(string, "Name:", "||"));
printf( "%s", strnext(string, "Suspect:", "||"));
printf( "%s", strnext(string, "Location:", "||"));
printf( "%s", strnext(string, "Combat:", ""));

//prints:
Evil Man
Drama Queen
Notting Hills
Ninja
Edited.
Idk how should i do the -1 check for strfind.. x)
Reply


Messages In This Thread
Get the next word in a string? - by linuxthefish - 18.08.2011, 13:17
Re: Get the next word in a string? - by Jefff - 18.08.2011, 14:30
Re: Get the next word in a string? - by RyDeR` - 18.08.2011, 14:46
Re: Get the next word in a string? - by iPLEOMAX - 18.08.2011, 15:22
Re: Get the next word in a string? - by linuxthefish - 18.08.2011, 18:02

Forum Jump:


Users browsing this thread: 3 Guest(s)