Difference between revisions of "Sindex"
From SDU
(→Examples) |
(→Examples) |
||
Line 28: | Line 28: | ||
set_return_data("Match!"); | set_return_data("Match!"); | ||
} | } | ||
+ | |||
// Regular expression example | // Regular expression example | ||
+ | |||
sindex(action_desc, "(wf:[0-9]+)"); | sindex(action_desc, "(wf:[0-9]+)"); | ||
// This will print "sindex: 2" | // This will print "sindex: 2" | ||
+ | |||
printf("sindex: %d\n", sindex("This is a test message.", "is")); | printf("sindex: %d\n", sindex("This is a test message.", "is")); |
Latest revision as of 16:02, 3 March 2009
To make corrections or additions to this article, select the edit tab above.
To discuss or ask questions about this article, select the discussion tab above.
To discuss or ask questions about this article, select the discussion tab above.
Overview
A spel function which, although much diffrent in syntax, works similar to regex (Regular Expression) string matches found in most other programming languages.
Returns the index of the first appearance of the pattern in the search string. Patterns can be regular expressions.
Usage
int sindex(string search_str, string pattern);
Returns the index of the first appearance of PATTERN in the SEARCH_STR.
Results
Sindex will return a -1 is no match is found or the position of the first character of the match. Position count starts from zero.
Examples
- If statement using sindex (matching a string against a string)
if (sindex("test string", "test")==0) {return;}
- Pushing the results of sindex into a variable (matching a string in another variable)
int results; results=sindex(group.id, "776B094702EABB4B87F04A139E72D44B"); if (results==-1) { set_return_data("No Match"); } else { set_return_data("Match!"); }
// Regular expression example
sindex(action_desc, "(wf:[0-9]+)");
// This will print "sindex: 2"
printf("sindex: %d\n", sindex("This is a test message.", "is"));