51 lines
1.5 KiB
Plaintext
51 lines
1.5 KiB
Plaintext
// XProfan can use StringParts, so the results here
|
|
// are the comma separated positions of the parts or 0
|
|
Proc Contains
|
|
Parameters string content, part
|
|
var string results = "0"
|
|
var long posi = 1
|
|
posi = InStr(part,content,posi)
|
|
if posi <> 0
|
|
results = str$(posi)
|
|
repeat
|
|
posi = InStr(part,content,posi+1)
|
|
case posi <> 0 : results = results + "," + str$(posi)
|
|
until posi == 0
|
|
endif
|
|
Return results
|
|
EndProc
|
|
|
|
Proc StartsWith
|
|
Parameters string content, part
|
|
Return if(Left$(content,Len(part)) == part, 1, 0)
|
|
EndProc
|
|
|
|
Proc EndsWith
|
|
Parameters string content, part
|
|
Return if(Right$(content,Len(part)) == part, 1, 0)
|
|
'Return if(Left$(content,Len(content)-Len(part)+1) == part, 1, 0)
|
|
EndProc
|
|
|
|
var string theContent = "foobar"
|
|
var string thePart = "foo"
|
|
Print "Starts with: "
|
|
Print " ("+thePart+" in "+theContent+") "+if(StartsWith(theContent,thePart),"Yes","No")
|
|
thePart = "back"
|
|
Print " ("+thePart+" in "+theContent+") "+if(StartsWith(theContent,thePart),"Yes","No")
|
|
|
|
theContent = "foooooobar"
|
|
Print "Contains: "
|
|
Print " ("+thePart+" in "+theContent+") "+ Contains(theContent,thePart)
|
|
thePart = "o"
|
|
Print " ("+thePart+" in "+theContent+") "+ Contains(theContent,thePart)
|
|
|
|
theContent = "foobar"
|
|
thePart = "back"
|
|
Print "Ends with: "
|
|
Print " ("+thePart+" in "+theContent+") "+if(EndsWith(theContent,thePart),"Yes","No")
|
|
thePart = "bar"
|
|
Print " ("+thePart+" in "+theContent+") "+if(EndsWith(theContent,thePart),"Yes","No")
|
|
|
|
waitkey
|
|
end
|