String matching: Difference between revisions
Content deleted Content added
mNo edit summary |
No edit summary |
||
Line 680: | Line 680: | ||
print( "s1 ends with s2: ", select( 2, string.find( s1, s2 ) ) == string.len( s1 ) ) |
print( "s1 ends with s2: ", select( 2, string.find( s1, s2 ) ) == string.len( s1 ) ) |
||
print( "s1 ends with s3: ", select( 2, string.find( s1, s3 ) ) == string.len( s1 ) )</lang> |
print( "s1 ends with s3: ", select( 2, string.find( s1, s3 ) ) == string.len( s1 ) )</lang> |
||
=={{header|NetRexx}}== |
|||
<lang NetRexx>/* NetRexx */ |
|||
options replace format comments java crossref savelog symbols |
|||
lipsum = '' |
|||
x_ = 0 |
|||
x_ = x_ + 1; lipsum[0] = x_; lipsum[x_] = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' |
|||
x_ = x_ + 1; lipsum[0] = x_; lipsum[x_] = lipsum[1].reverse |
|||
srch = '' |
|||
srch[1] = 'Lorem ipsum dolor sit amet' |
|||
srch[2] = 'consectetur adipisicing elit' |
|||
srch[3] = 'dolore magna aliqua.' |
|||
loop j_ = 1 to lipsum[0] |
|||
x1 = lipsum[j_].pos(srch[1]) |
|||
x2 = lipsum[j_].pos(srch[2]) |
|||
x3 = lipsum[j_].lastpos(srch[3]) |
|||
report(x1 = 1, lipsum[j_], srch[1], 'Test string starts with search string:', 'Test string does not start with search string:') |
|||
report(x2 > 0, lipsum[j_], srch[2], 'Search string located in test string at position:' x2, 'Search string not found within test string:') |
|||
report(x3 \= srch[3].length, lipsum[j_], srch[3], 'Test string ends with search string:', 'Test string does not start with search string:') |
|||
end j_ |
|||
many = '' |
|||
x_ = 0 |
|||
x_ = x_ + 1; many[0] = x_; many[x_] = 'How many times does "many times" occur in this string?' |
|||
x_ = x_ + 1; many[0] = x_; many[x_] = 'How often does "many times" occur in this string?' |
|||
x_ = x_ + 1; many[0] = x_; many[x_] = 'How often does it occur in this string?' |
|||
srch[4] = 'many times' |
|||
loop j_ = 1 to many[0] |
|||
o_ = 0 |
|||
k_ = 0 |
|||
loop label dups until o_ = 0 |
|||
o_ = many[j_].pos(srch[4], o_ + 1) |
|||
if o_ \= 0 then k_ = k_ + 1 |
|||
end dups |
|||
report(k_ > 0, many[j_], srch[4], 'Number of times search string occurs:' k_, 'Search string not found') |
|||
end j_ |
|||
method report(state = boolean, ts, ss, testSuccess, testFailure) public static |
|||
if state then say testSuccess |
|||
else say testFailure |
|||
say ' Test string:' ts |
|||
say ' Search string:' ss |
|||
say |
|||
return |
|||
</lang> |
|||
=={{header|Objective-C}}== |
=={{header|Objective-C}}== |