Welcome to the Creatures Wiki! Log in and join the community.
SINS
Jump to navigation
Jump to search
SINS is a DS-only CAOS command which searches within a string.
Usage[edit]
Syntax: SINS haystack (string) from (int) needle (string)
Searches for needle in haystack from the index from. Returns, as an integer, the index in haystack of the first instance of needle, or -1 if not found. You can then use SUBS to fetch relevant parts of the string.
String indices start at 1. This command is case sensitive. See LOWA and UPPA to convert case.
This is similar to the C function strstr()
.
Example[edit]
SETS va00 "shush" OUTV SINS va00 1 "sh" 1 OUTV SINS va00 2 "sh" 4 OUTV SINS va00 5 "sh" -1
Implement SINS va00 va01 va02, placing the result in va03:
* assume: STRL va02 le STRL va00; va01 gt 0 && va01 le STRL va00. SETV va03 -1 SETV va04 1 LOOP DOIF va04 ne STRL va02 DOIF CHAR va00 va01 eq CHAR va02 va04 DOIF va03 eq -1 SETV va03 va01 ENDI ADDV va04 1 ELSE SETV va04 1 SETV va03 -1 ENDI ENDI ADDV va01 1 UNTL va01 eq STRL va00