Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
54
Task/String-matching/Picat/string-matching.picat
Normal file
54
Task/String-matching/Picat/string-matching.picat
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import util.
|
||||
|
||||
go =>
|
||||
S1 = "string second",
|
||||
S2 = "string",
|
||||
|
||||
% - Determining if the first string starts with second string
|
||||
println("Using find/4"),
|
||||
if find(S1,S2,1,_) then
|
||||
println("S1 starts with S2")
|
||||
else
|
||||
println("S1 does not start with S2")
|
||||
end,
|
||||
|
||||
println("Using append/3"),
|
||||
if append(S2,_,S1) then
|
||||
println("S1 starts with S2")
|
||||
else
|
||||
println("S1 does not start with S2")
|
||||
end,
|
||||
|
||||
% - Determining if the first string contains the second string at any location
|
||||
S3 = "this is a string",
|
||||
S4 = "is a",
|
||||
if find(S3,S4,Start4,End4) then
|
||||
printf("S3 contains S4 at pos %d..%d\n", Start4,End4)
|
||||
else
|
||||
println("S3 does not contain S4")
|
||||
end,
|
||||
|
||||
% - Determining if the first string ends with the second string
|
||||
S5 = "this is a string",
|
||||
S6 = "string",
|
||||
if find(S5,S6,Start6,S5.length) then
|
||||
printf("S5 ends with S6, startpos: %d\n",Start6)
|
||||
else
|
||||
println("S5 does not end with S6")
|
||||
end,
|
||||
|
||||
if append(_,S6,S5) then
|
||||
println("S5 ends with S6")
|
||||
else
|
||||
println("S5 does not end with S6")
|
||||
end,
|
||||
|
||||
S7 = "this is a string or a string",
|
||||
S8 = "a string",
|
||||
All = findall([Start8,End8], find(S7,S8,Start8,End8)),
|
||||
println(positions=All),
|
||||
|
||||
% searching for " "
|
||||
All2 = findall([Start9,End9], find(S7," ",Start9,End9)),
|
||||
println(positions=All2),
|
||||
nl.
|
||||
Loading…
Add table
Add a link
Reference in a new issue