String matching: Difference between revisions

m
curation
(add language: Retro)
m (curation)
Line 8:
 
Optional requirements:
A)# Print the location of the match for part 2
B)# Handle multiple occurrences of a string for part 2.
 
=={{header|ALGOL 68}}==
{{trans|python}}
 
{{works with|ALGOL 68|Revision 1 - no extensions to language used}}
 
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - string in string is non-standard?}}
Line 39 ⟶ 38:
TFFT -1 +1 +3
</pre>
 
=={{header|C++}}==
<lang cpp>#include <string>
 
<lang cpp>
#include <string>
using namespace std;
 
Line 55 ⟶ 53:
s1.find(s2)//returns string::npos
int loc=s2.find(s3)//returns 0
loc=s2.find(s3,loc+1)//returns 2</lang>
</lang>
 
=={{header|J}}==
 
<lang j>startswith=: ] -: ({.~ #)
contains=: +./@:E.~
Line 94 ⟶ 90:
 
=={{header|Java}}==
<lang java>"abcd".startsWith("ab") //returns true
 
<lang java>
"abcd".startsWith("ab") //returns true
"abcd".endsWith("zn") //returns false
"abab".contains("bb") //returns false
Line 102 ⟶ 96:
int loc = "abab".indexOf("bb") //returns -1
loc = "abab".indexOf("ab") //returns 0
loc = "abab".indexOf("ab",loc+1) //returns 2</lang>
</lang>
 
=={{header|Objective-C}}==
<lang objc>[@"abcd" hasPrefix:@"ab"] //returns true
 
<lang objc>
[@"abcd" hasPrefix:@"ab"] //returns true
[@"abcd" hasSuffix:@"zn"] //returns false
int loc = [@"abab" rangeOfString:@"bb"].location //returns -1
loc = [@"abab" rangeOfString:@"ab"].location //returns 0
loc = [@"abab" rangeOfString:@"ab" options:0 range:NSMakeRange(loc+1, [@"abab" length]-(loc+1))].location //returns 2</lang>
</lang>
=={{header|PureBasic}}==
<lang PureBasic>Procedure StartsWith(String1$, String2$)
Line 139 ⟶ 129:
 
=={{header|Python}}==
<lang python>"abcd".startswith("ab") #returns true
 
<lang python>
"abcd".startswith("ab") #returns true
"abcd".endswith("zn") #returns false
"bb" in "abab" #returns false
Line 147 ⟶ 135:
loc = "abab".find("bb") #returns -1
loc = "abab".find("ab") #returns 0
loc = "abab".find("ab",loc+1) #returns 2</lang>
</lang>
 
=={{header|Retro}}==
 
<lang Retro>with strings'
 
Anonymous user