Strip comments from a string: Difference between revisions

Added solution for Action!
(Added solution for Action!)
Line 46:
apples ; pears
apples ; pears # and bananas
</pre>
 
=={{header|Action!}}==
<lang Action!>PROC Strip(CHAR ARRAY text,chars,result)
BYTE i,j,pos,found
 
pos=text(0)
FOR i=1 TO text(0)
DO
found=0
FOR j=1 TO chars(0)
DO
IF text(i)=chars(j) THEN
found=1 EXIT
FI
OD
IF found THEN
pos=i-1 EXIT
FI
OD
WHILE pos>0 AND text(pos)='
DO
pos==-1
OD
SCopyS(result,text,1,pos)
RETURN
 
PROC Test(CHAR ARRAY text,chars)
CHAR ARRAY result(255)
 
Strip(text,chars,result)
PrintF("""%S"", ""%S"" -> ""%S""%E%E",text,chars,result)
RETURN
 
PROC Main()
Test("apples, pears # and bananas","#;")
Test("apples, pears ; and bananas","#;")
Test("qwerty # asdfg ; zxcvb","#")
Test("qwerty # asdfg ; zxcvb",";")
Test(" ;this is a comment","#;")
Test("#this is a comment","#;")
Test(" ",";")
Test("","#")
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Strip_comments_from_a_string.png Screenshot from Atari 8-bit computer]
<pre>
"apples, pears # and bananas", "#;" -> "apples, pears"
 
"apples, pears ; and bananas", "#;" -> "apples, pears"
 
"qwerty # asdfg ; zxcvb", "#" -> "qwerty"
 
"qwerty # asdfg ; zxcvb", ";" -> "qwerty # asdfg"
 
" ;this is a comment", "#;" -> ""
 
"#this is a comment", "#;" -> ""
 
" ", ";" -> ""
 
"", "#" -> ""
</pre>
 
Anonymous user