Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
73
Task/Substring/Action-/substring.action
Normal file
73
Task/Substring/Action-/substring.action
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
BYTE FUNC FindC(CHAR ARRAY text CHAR c)
|
||||
BYTE i
|
||||
|
||||
i=1
|
||||
WHILE i<=text(0)
|
||||
DO
|
||||
IF text(i)=c THEN
|
||||
RETURN (i)
|
||||
FI
|
||||
i==+1
|
||||
OD
|
||||
RETURN (0)
|
||||
|
||||
BYTE FUNC FindS(CHAR ARRAY text,sub)
|
||||
BYTE i,j,found
|
||||
|
||||
i=1
|
||||
WHILE i<=text(0)-sub(0)+1
|
||||
DO
|
||||
found=0
|
||||
FOR j=1 TO sub(0)
|
||||
DO
|
||||
IF text(i+j-1)#sub(j) THEN
|
||||
found=0 EXIT
|
||||
ELSE
|
||||
found=1
|
||||
FI
|
||||
OD
|
||||
IF found THEN
|
||||
RETURN (i)
|
||||
FI
|
||||
i==+1
|
||||
OD
|
||||
RETURN (0)
|
||||
|
||||
PROC Main()
|
||||
CHAR ARRAY text="qwertyuiop"
|
||||
CHAR ARRAY sub="tyu"
|
||||
CHAR ARRAY res(20)
|
||||
BYTE n,m
|
||||
CHAR c
|
||||
|
||||
PrintF("Original string:%E ""%S""%E%E",text)
|
||||
|
||||
n=3 m=5
|
||||
SCopyS(res,text,n,n+m-1)
|
||||
PrintF("Substring start from %B and length %B:%E ""%S""%E%E",n,m,res)
|
||||
|
||||
n=4
|
||||
SCopyS(res,text,n,text(0))
|
||||
PrintF("Substring start from %B up to the end:%E ""%S""%E%E",n,res)
|
||||
|
||||
SCopyS(res,text,1,text(0)-1)
|
||||
PrintF("Whole string without the last char:%E ""%S""%E%E",res)
|
||||
|
||||
c='w m=4
|
||||
n=FindC(text,c)
|
||||
IF n=0 THEN
|
||||
PrintF("Character '%C' not found in string%E%E",c)
|
||||
ELSE
|
||||
SCopyS(res,text,n,n+m-1)
|
||||
PrintF("Substring start from '%C' and len %B:%E ""%S""%E%E",c,m,res)
|
||||
FI
|
||||
|
||||
n=FindS(text,sub)
|
||||
m=6
|
||||
IF n=0 THEN
|
||||
PrintF("String ""%S"" not found in string%E%E",sub)
|
||||
ELSE
|
||||
SCopyS(res,text,n,n+m-1)
|
||||
PrintF("Substring start from '%S' and len %B: ""%S""%E%E",sub,m,res)
|
||||
FI
|
||||
RETURN
|
||||
Loading…
Add table
Add a link
Reference in a new issue