String matching: Difference between revisions
Content deleted Content added
m Mark as basic data operation |
m alphabetized list |
||
Line 169:
Contains Test ( Google,msn ) : 0
</lang>
=={{header|C++}}==▼
<lang cpp>#include <string>▼
using namespace std;▼
string s1="abcd";▼
string s2="abab";▼
string s3="ab";▼
//Beginning▼
s1.compare(0,s3.size(),s3)==0;▼
//End▼
s1.compare(s1.size()-s3.size(),s3.size(),s3)==0;▼
//Anywhere▼
s1.find(s2)//returns string::npos▼
int loc=s2.find(s3)//returns 0▼
loc=s2.find(s3,loc+1)//returns 2</lang>▼
=={{header|C sharp|C#}}==
Line 187 ⟶ 203:
}
</lang>
▲=={{header|C++}}==
▲<lang cpp>#include <string>
▲using namespace std;
▲string s1="abcd";
▲string s2="abab";
▲string s3="ab";
▲//Beginning
▲s1.compare(0,s3.size(),s3)==0;
▲//End
▲s1.compare(s1.size()-s3.size(),s3.size(),s3)==0;
▲//Anywhere
▲s1.find(s2)//returns string::npos
▲int loc=s2.find(s3)//returns 0
▲loc=s2.find(s3,loc+1)//returns 2</lang>
=={{header|Clojure}}==
Line 509:
loc = "abab".find("ab") #returns 0
loc = "abab".find("ab",loc+1) #returns 2</lang>
=={{header|Retro}}==▼
<lang Retro>with strings'▼
: startsWith? ( $1 $2 - f )▼
dup getLength [ swap ] dip 0 swap getSubset compare ;▼
"abcdefghijkl" "abcde" startsWith?▼
"abcdefghijkl" "bcd" startsWith?▼
"abcdefghijkl" "bcd" search▼
"abcdefghijkl" "zmq" search▼
: endsWith? ( $1 $2 - f )▼
swap dup getLength + over getLength - compare ;▼
"abcdefghijkl" "ijkl" endsWith?▼
"abcdefghijkl" "abc" endsWith?</lang>▼
=={{header|REXX}}==
Line 619 ⟶ 637:
'abab'.index('ab') #returns 0
'abab'.index('ab', 1) #returns 2</lang>
▲=={{header|Retro}}==
▲<lang Retro>with strings'
▲: startsWith? ( $1 $2 - f )
▲ dup getLength [ swap ] dip 0 swap getSubset compare ;
▲"abcdefghijkl" "abcde" startsWith?
▲"abcdefghijkl" "bcd" startsWith?
▲"abcdefghijkl" "bcd" search
▲"abcdefghijkl" "zmq" search
▲: endsWith? ( $1 $2 - f )
▲ swap dup getLength + over getLength - compare ;
▲"abcdefghijkl" "ijkl" endsWith?
▲"abcdefghijkl" "abc" endsWith?</lang>
=={{header|Scala}}==
Line 674:
puts "needle matched at index [lindex $location 0]"
}</lang>
=={{header|TUSCRIPT}}==
<lang tuscript>
Line 701 ⟶ 702:
</lang>
Output:
<pre>string1 >Rosetta Code▼
▲string1 >Rosetta Code
string2 >Code
Rosetta Code not starts with Code
|