September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
34
Task/String-matching/360-Assembly/string-matching.360
Normal file
34
Task/String-matching/360-Assembly/string-matching.360
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
* String matching 04/04/2017
|
||||
STRMATCH CSECT
|
||||
USING STRMATCH,R15
|
||||
XPRNT SS,L'SS
|
||||
*
|
||||
CLC SS(L'S1),S1
|
||||
BNE NOT1
|
||||
XPRNT =C'-- STARTS WITH',14
|
||||
XPRNT S1,L'S1
|
||||
NOT1 EQU *
|
||||
*
|
||||
CLC SS+L'SS-L'S2(L'S2),S2
|
||||
BNE NOT2
|
||||
XPRNT =C'-- ENDS WITH',12
|
||||
XPRNT S2,L'S2
|
||||
NOT2 EQU *
|
||||
*
|
||||
LA R0,L'SS-L'S3+1
|
||||
LA R1,SS
|
||||
LOOP CLC 0(L'S3,R1),S3
|
||||
BNE NOT3
|
||||
XPRNT =C'-- CONTAINS',11
|
||||
XPRNT S3,L'S3
|
||||
NOT3 LA R1,1(R1)
|
||||
BCT R0,LOOP
|
||||
*
|
||||
BR R14
|
||||
SS DC CL6'ABCDEF'
|
||||
S1 DC CL2'AB'
|
||||
S2 DC CL2'EF'
|
||||
S3 DC CL2'CD'
|
||||
PG DC CL80' '
|
||||
YREGS
|
||||
END STRMATCH
|
||||
|
|
@ -1,25 +1,24 @@
|
|||
#import system.
|
||||
#import extensions.
|
||||
import extensions.
|
||||
|
||||
#symbol program =
|
||||
program =
|
||||
[
|
||||
#var s := "abcd".
|
||||
var s := "abcd".
|
||||
|
||||
console writeLine:s:" starts with ab: ":(s startingWith:"ab" literal).
|
||||
console writeLine:s:" starts with cd: ":(s startingWith:"cd" literal).
|
||||
console printLine(s," starts with ab: ",s startingWith:"ab").
|
||||
console printLine(s," starts with cd: ",s startingWith:"cd").
|
||||
|
||||
console writeLine:s:" ends with ab: ":(s endingWith:"ab" literal).
|
||||
console writeLine:s:" ends with cd: ":(s endingWith:"cd" literal).
|
||||
console printLine(s," ends with ab: ",s endingWith:"ab").
|
||||
console printLine(s," ends with cd: ",s endingWith:"cd").
|
||||
|
||||
console writeLine:s:" contains ab: ":(s containing:"ab" literal).
|
||||
console writeLine:s:" contains bc: ":(s containing:"bc" literal).
|
||||
console writeLine:s:" contains cd: ":(s containing:"cd" literal).
|
||||
console writeLine:s:" contains az: ":(s containing:"az" literal).
|
||||
console printLine(s," contains ab: ",s containing:"ab").
|
||||
console printLine(s," contains bc: ",s containing:"bc").
|
||||
console printLine(s," contains cd: ",s containing:"cd").
|
||||
console printLine(s," contains az: ",s containing:"az").
|
||||
|
||||
console writeLine:s:" index of az: ":(s indexOf:"az" &at:0 literal).
|
||||
console writeLine:s:" index of cd: ":(s indexOf:"cd" &at:0 literal).
|
||||
console writeLine:s:" index of bc: ":(s indexOf:"bc" &at:0 literal).
|
||||
console writeLine:s:" index of ab: ":(s indexOf:"ab" &at:0 literal).
|
||||
console printLine(s," index of az: ",s indexOf:"az" at:0).
|
||||
console printLine(s," index of cd: ",s indexOf:"cd" at:0).
|
||||
console printLine(s," index of bc: ",s indexOf:"bc" at:0).
|
||||
console printLine(s," index of ab: ",s indexOf:"ab" at:0).
|
||||
|
||||
console readChar.
|
||||
].
|
||||
|
|
|
|||
9
Task/String-matching/Gambas/string-matching.gambas
Normal file
9
Task/String-matching/Gambas/string-matching.gambas
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
Public Sub Main()
|
||||
Dim sString1 As String = "Hello world"
|
||||
Dim sString2 As String = "Hello"
|
||||
|
||||
Print sString1 Begins Left(sString2, 5) 'Determine if the first string starts with second string
|
||||
If InStr(sString1, sString2) Then Print "True" Else Print "False" 'Determine if the first string contains the second string at any location
|
||||
Print sString1 Ends Left(sString2, 5) 'Determine if the first string ends with the second string
|
||||
|
||||
End
|
||||
12
Task/String-matching/Kotlin/string-matching.kotlin
Normal file
12
Task/String-matching/Kotlin/string-matching.kotlin
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// version 1.0.6
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val s1 = "abracadabra"
|
||||
val s2 = "abra"
|
||||
println("$s1 begins with $s2 : ${s1.startsWith(s2)}")
|
||||
println("$s1 ends with $s2 : ${s1.endsWith(s2)}")
|
||||
val b = s2 in s1
|
||||
print("$s1 contains $s2 : $b")
|
||||
if (b) println(" at locations ${s1.indexOf(s2) + 1} and ${s1.lastIndexOf(s2) + 1}")
|
||||
else println()
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
parse arg A B; LB=length(B) /*obtain A and B from the command line.*/
|
||||
say 'string A = ' A /*display string A to the terminal.*/
|
||||
say 'string B = ' B /* " " B " " " */
|
||||
say
|
||||
say copies('░', 70)
|
||||
if left(A, LB)==B then say 'string A starts with string B'
|
||||
else say "string A doesn't start with string B"
|
||||
say /* [↓] another method using COMPARE BIF*/
|
||||
|
|
@ -17,12 +17,11 @@ say
|
|||
if right(A, LB)==b then say 'string A ends with string B'
|
||||
else say "string A doesn't end with string B"
|
||||
say
|
||||
$=; p=0; do until p==0; p=pos(B, A, p+1)
|
||||
if p\==0 then $=$',' p
|
||||
end /*until ···*/
|
||||
$=space(strip($,'L',",")) /*elide extra blanks and leading comma.*/
|
||||
#=words($)
|
||||
$=; p=0; do until p==0; p=pos(B, A, p+1)
|
||||
if p\==0 then $=$',' p
|
||||
end /*until*/
|
||||
$=space(strip($, 'L', ",")) /*elide extra blanks and leading comma.*/
|
||||
#=words($) /*obtain number of words in $ string.*/
|
||||
if #==0 then say "string A doesn't contain string B"
|
||||
else say 'string A contains string B ' # " time"left('s', #>1),
|
||||
"(at position"left('s', #>1) $")"
|
||||
/*stick a fork in it, we're all done. */
|
||||
else say 'string A contains string B ' # " time"left('s', #>1),
|
||||
"(at position"left('s', #>1) $")" /*stick a fork in it, we're done*/
|
||||
|
|
|
|||
7
Task/String-matching/Rust/string-matching-2.rust
Normal file
7
Task/String-matching/Rust/string-matching-2.rust
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fn main(){
|
||||
let hello = String::from("Hello world");
|
||||
println!(" Start with \"he\" {} \n Ends with \"rd\" {}\n Contains \"wi\" {}",
|
||||
hello.starts_with("He"),
|
||||
hello.ends_with("ld"),
|
||||
hello.contains("wi"));
|
||||
}
|
||||
|
|
@ -5,13 +5,12 @@
|
|||
(put-line `@big is shorter than @small`))
|
||||
((str= big small)
|
||||
(put-line `@big and @small are equal`))
|
||||
((match-str big small)
|
||||
((starts-with small big)
|
||||
(put-line `@small is a prefix of @big`))
|
||||
((match-str big small -1)
|
||||
((ends-with small big)
|
||||
(put-line `@small is a suffix of @big`))
|
||||
(t (let ((pos (search-str big small)))
|
||||
(if pos
|
||||
(put-line `@small occurs in @big at position @pos`)
|
||||
(put-line `@small does not occur in @big`))))))
|
||||
(t (iflet ((pos (search-str big small)))
|
||||
(put-line `@small occurs in @big at position @pos`)
|
||||
(put-line `@small does not occur in @big`)))))
|
||||
(otherwise
|
||||
(put-line `usage: @(ldiff *full-args* *args*) <bigstring> <smallstring>`)))
|
||||
|
|
|
|||
3
Task/String-matching/Zkl/string-matching-1.zkl
Normal file
3
Task/String-matching/Zkl/string-matching-1.zkl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fcn f(text,p){ if(text.find(p)==0)println("Yep") else println("Nope") }
|
||||
f("foobar","foo") //--> Yep
|
||||
f("foobar","bar") //--> Nope
|
||||
3
Task/String-matching/Zkl/string-matching-2.zkl
Normal file
3
Task/String-matching/Zkl/string-matching-2.zkl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fcn f(text,p){ if(Void!=(n:=text.find(p)))println("Contained @",n) else println("Nope") }
|
||||
f("foobar","ob") //--> Contained @2
|
||||
f("foobar","food") //--> Nope
|
||||
7
Task/String-matching/Zkl/string-matching-3.zkl
Normal file
7
Task/String-matching/Zkl/string-matching-3.zkl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fcn f(text,p){
|
||||
if( Void!=(n:=text.rfind(p)) and n+p.len()==text.len() )
|
||||
println("tail gunner") else println("Nope")
|
||||
}
|
||||
f("foobar","r"); f("foobar","ar"); //--> tail gunners
|
||||
f("foobar","ob"); //--> Nope
|
||||
f("foobarfoobar","bar"); //--> tail gunner
|
||||
Loading…
Add table
Add a link
Reference in a new issue