String matching: Difference between revisions
Content added Content deleted
m (added whitespace.) |
No edit summary |
||
Line 4,131: | Line 4,131: | ||
yes |
yes |
||
no |
no |
||
</pre> |
|||
=={{header|XProfan}}== |
|||
<lang XProfan> |
|||
// 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</lang> |
|||
{{out}} |
|||
<pre> |
|||
Starts with: |
|||
(foo in foobar) Yes |
|||
(back in foobar) No |
|||
Contains: |
|||
(back in foooooobar) 0 |
|||
(o in foooooobar) 2,3,4,5,6,7 |
|||
Ends with: |
|||
(back in foobar) No |
|||
(bar in foobar) Yes |
|||
</pre> |
</pre> |
||