Jump to content

String matching: Difference between revisions

m
→‎{{header|D}}: + D & fix header
(Go header error)
m (→‎{{header|D}}: + D & fix header)
Line 255:
([(. "abcd" startsWith "ab") true] [(. "abcd" endsWith "zn") false] [(. "abab" contains "bb") false] [(. "abab" contains "ab") true] [(. "abab" indexOf "bb") -1] [(let [loc (. "abab" indexOf "ab")] (. "abab" indexOf "ab" (dec loc))) 0])</lang>
 
=={{header|D}}==
<lang d>import std.stdio, std.algorithm ;
void main() {
writeln("abcd".startsWith("ab")) ; // true
writeln("abcd".endsWith("zn")) ; // false
writeln("abab".find("bb")) ; // empty array (no match)
writeln("abcd".find("bc")) ; // "bcd" (substring start at match)
writeln("abab".indexOf("bb")) ; // -1 (no match)
writeln("abab".indexOf("ba")) ; // 1 (index of 1st match)
// above function from algorithm module not only work for string but
// also other array and range
writeln([1,2,3].indexOf(3)) ; // 2
writeln([1,2,3].indexOf([2,3])) ; // 1
}</lang>
=={{header|E}}==
 
<lang edefe>def f(string1, string2) {
println(string1.startsWith(string2))
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.