Strip comments from a string: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|J}}: make output match expression generating output) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 31:
=={{header|11l}}==
<
V? p = line.find(sep)
I p != N
Line 39:
print(remove_comments(‘apples ; pears # and bananas’, (‘;’, ‘#’)))
print(remove_comments(‘apples ; pears # and bananas’, ‘#’))
print(remove_comments(‘apples ; pears # and bananas’, ‘!’))</
{{out}}
Line 49:
=={{header|68000 Assembly}}==
<
;prints a string but stops at the comment character
;INPUT: D7 = comment character(s) of choice
Line 109:
TestString:
dc.b "apples ; pears # and bananas",0</
=={{header|Action!}}==
<
BYTE i,j,pos,found
Line 152:
Test(" ",";")
Test("","#")
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Strip_comments_from_a_string.png Screenshot from Atari 8-bit computer]
Line 174:
=={{header|Ada}}==
<
procedure Program is
Comment_Characters : String := "#;";
Line 193:
end;
end loop;
end Program;</
=={{header|Aime}}==
<
{
b.size(b.look(0, ";#")).bf_drop(" \t").bb_drop(" \t");
Line 208:
0;
}</
=={{header|ALGOL 68}}==
Line 214:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}}
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d]}}
<
PROC trim comment = (STRING line, CHAR marker)STRING:(
Line 239:
grep in string(re marker, line, index, NIL);
print((q, line[:index-1], q, new line))
END CO</
Output:
<pre>
Line 251:
=={{header|ALGOL W}}==
Leading and trailing spaces are removed from the result, as per the March 29 2011 task version.
<
% determines the non-comment portion of the string s, startPos and endPos are %
% returned set to the beginning and ending character positions (indexed from 0) %
Line 293:
testStripComments( " apples, pears" )
end
end.</
{{out}}
<pre>
Line 303:
=={{header|Applesoft BASIC}}==
<
20 S$(1)="APPLES, PEARS # AND BANANAS"
30 S$(2)="APPLES, PEARS ; AND BANANAS"
Line 328:
250 IF A$ = " " THEN NEXT I
260 LET S$ = MID$(S$, 1, I)
270 RETURN</
=={{header|Arturo}}==
<
strip replace str {/[#;].+/} ""
]
Line 338:
loop ["apples, pears # and bananas", "apples, pears ; and bananas"] 'str [
print [str "->" stripComments str]
]</
{{out}}
Line 346:
=={{header|AutoHotkey}}==
<
str := "apples, pears # and bananas"
str2:= "apples, pears, `; and bananas" ; needed to escape the ; since that is AHK's comment marker
Line 364:
}
return String1
}</
Output:
<pre>
Line 373:
=={{header|AutoIt}}==
It was always said in discussion, the task is not really stripping comments. It's only a truncation.
<syntaxhighlight lang="autoit">
Dim $Line1 = "apples, pears # and bananas"
Dim $Line2 = "apples, pears ; and bananas"
Line 391:
Next
EndFunc ;==>_StripAtMarker
</syntaxhighlight>
Output:
<pre>
Line 405:
That means: the comment starts with the first semicolon outside a string.
<syntaxhighlight lang="autoit">
Dim $aLines[4] = _
[ _
Line 462:
Next
EndFunc ;==>_LineStripComment
</syntaxhighlight>
Output:
<pre>
Line 488:
=={{header|AWK}}==
<
{
sub("[ \t]*[#;].*$","",$0);
print;
}</
=={{header|ANSI BASIC}}==
<
110 LET marker$="#;"
120 PRINT """";FNstripcomment$("apples, pears # and bananas", marker$);""""
Line 508:
210 NEXT I
220 LET FNstripcomment$=RTRIM$(text$)
230 END FUNCTION</
Output:
<pre>
Line 517:
=={{header|BQN}}==
<code>StripW</code> only removes spaces. <code>StripC</code> uses that in conjunction with a filter that removes comments.
<
StripC←StripW (¬·∨`∊⟜"#;")⊸/
•Show StripC " apples, pears # and bananas "
•Show StripC " apples, pears ; and bananas"</
<syntaxhighlight lang="text">"apples, pears"
"apples, pears"</
=={{header|Bracmat}}==
<
oranges, mangos ; and a durian"
: ?text
Line 546:
& !newText \n cleanUp$!text:?newText
& out$(str$!newText)
);</
Output:
<pre>
Line 553:
=={{header|C}}==
<
int main()
Line 578:
return 0;
}</
Output:
<pre>
Line 594:
=={{header|C sharp|C#}}==
<
using System.Text.RegularExpressions;
Line 604:
return Regex.Replace(str, delimiter + ".+", string.Empty).Trim();
}
</syntaxhighlight>
Sample output:
<pre>
Line 614:
=={{header|C++}}==
<
#include <string>
Line 636:
}
return 0;
}</
Sample output:
<pre>
Line 646:
=={{header|Clojure}}==
<
"apples "</
=={{header|COBOL}}==
{{works with|GnuCOBOL}}
<
program-id. StripComments.
Line 671:
unstring line-text delimited by "#" or ";" into line-text
display quote, function trim(line-text), quote
.</
{{out}}
<pre>"apples, pears"
Line 677:
=={{header|Common Lisp}}==
<
"Truncate s at the first occurrence of a character in cs."
(defun comment-char-p (c)
(some #'(lambda (x) (char= x c)) cs))
(let ((pos (position-if #'comment-char-p s)))
(subseq s 0 pos)))</
{{Out}}
Line 697:
=={{header|D}}==
<
string remove1LineComment(in string s, in string pat=";#") {
Line 709:
writeln(s, "\n====>\n", s.remove1LineComment());
}</
{{out}}
<pre>apples, pears # and bananas
Line 718:
=={{header|Delphi}}==
<
{$APPTYPE CONSOLE}
Line 735:
Writeln('apples, pears ; and bananas --> ' + DoStripComments('apples, pears ; and bananas',';'));
Readln;
end.</
=={{header|DWScript}}==
<
begin
var p := FindDelimiter('#;', s);
Line 747:
PrintLn(StripComments('apples, pears # and bananas'));
PrintLn(StripComments('apples, pears ; and bananas'));</
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">
-module( strip_comments_from_string ).
Line 767:
not_comment( $; ) -> false;
not_comment( _ ) -> true.
</syntaxhighlight>
{{out}}
<pre>
Line 777:
=={{header|F_Sharp|F#}}==
<
s
|> Seq.takeWhile (fun c -> c <> '#' && c <> ';')
|> Seq.map System.Char.ToString
|> Seq.fold (+) ""</
=={{header|Factor}}==
<
: strip-comments ( str -- str' )
[ "#;" member? not ] take-while "" like ;</
=={{header|Fantom}}==
Using a regular expression:
<
{
static Str removeComment (Str str)
Line 808:
echo (removeComment ("String with comment ; here"))
}
}</
=={{header|Forth}}==
Line 845:
: COMMENT-STRIP ( addr len -- addr 'len) -LEADING -COMMENT -TRAILING ;
</
<pre>S" apples, pears # and bananas" COMMENT-STRIP TYPE apples, pears ok
S" apples, pears ; and bananas" COMMENT-STRIP TYPE apples, pears ok</pre>
=={{header|Fortran}}==
<
module string_routines
!****************************************************
Line 893:
!****************************************************
end program main
!****************************************************</
output:
<pre>
Line 901:
=={{header|FreeBASIC}}==
<
Sub stripComment(s As String, commentMarkers As String)
Line 927:
Print
Print "Press any key to quit"
Sleep</
{{out}}
Line 938:
=={{header|Go}}==
<
import (
Line 964:
fmt.Printf("stripped: %q\n", stripComment(s))
}
}</
Output:
<pre>
Line 976:
=={{header|Groovy}}==
<
Testing:
<
assert 'apples, pears' == stripComments('apples, pears ; and bananas')</
=={{header|Haskell}}==
<
main = getContents >>=
mapM_ (putStrLn . takeWhile (`notElem` ms)) . lines</
=={{header|Icon}} and {{header|Unicon}}==
<
# return part of string up to first character in 'markers',
# or else the whole string if no comment marker is present
Line 999:
write (strip_comments ("apples, pears # and bananas", cset ("#;")))
write (strip_comments ("apples, pears ; and bananas", cset ("#;")))
end</
Output:
Line 1,009:
=={{header|Inform 7}}==
<
When play begins:
Line 1,019:
say "[T] -> ";
replace the regular expression "<#;>.*$" in T with "";
say "[T][line break]".</
Since square brackets have a special meaning in strings, Inform's regular expression syntax uses angle brackets for character grouping.
=={{header|J}}==
'''Solution 1''' (mask & filter): <
'''Solution 2''' (index & cut): <
'''Example''':<
"apples, pears"
strip ' apples, pears ; and bananas'
apples, pears</
=={{header|Java}}==
<
public class StripLineComments{
Line 1,055:
}
}
}</
=={{header|JavaScript}}==
===ES5===
<
var re1 = /^\s+|\s+$/g; // Strip leading and trailing spaces
var re2 = /\s*[#;].+$/g; // Strip everything after # or ; to the end of the line, including preceding spaces
Line 1,070:
alert(stripComments(s1) + '\n' + stripComments(s2));
</syntaxhighlight>
A more efficient version that caches the regular expressions in a closure:
<
var re1 = /^\s+|\s+$/g;
var re2 = /\s*[#;].+$/g;
Line 1,081:
};
}());
</syntaxhighlight>
A difference with the two versions is that in the first, all declarations are processed before code is executed so the function declaration can be after the code that calls it. However in the second example, the expression creating the function must be executed before the function is available, so it must be before the code that calls it.
===ES6===
<
'use strict';
Line 1,146:
// MAIN ---
return main();
})();</
{{Out}}
<pre>apples, pears
Line 1,153:
=={{header|jq}}==
If your version of jq has regex support, the task can be accomplished with the following one-liner:
<
Otherwise, we can define strip_comment as a jq filter, as follows. For clarity, the helper functions are presented as top-level functions.
<
def is_whitespace: . as $in | " \n\r\f\t" | index($in);
Line 1,176:
end ) as $ix
| if $ix then .[0:$ix] else . end
| trim;</
'''Example''':
<
{{out}}
<
=={{header|Julia}}==
<tt>striplinecomment</tt> is designed to be flexible and robust. By default <tt>#</tt> and <tt>;</tt> are considered comment defining characters, but any characters can be used by passing them as the string <tt>cchars</tt>. All such characters are escaped in the regular expression used to eliminate comments to allow characters special to the Regex language (e.g. <tt>^</tt>, <tt>$</tt>, <tt>[</tt>) to be used as a comment character.
<syntaxhighlight lang="julia">
using Printf
Line 1,209:
println(" \"", s, "\"")
end
</syntaxhighlight>
{{out}}
Line 1,233:
It then removes whitespace from the beginning and end of the resulting string:
<
val r = Regex("""(/\*.*\*/|//.*$)""")
Line 1,247:
)
for (string in strings) println(stripComments(string))
}</
{{out}}
Line 1,258:
=={{header|Liberty BASIC}}==
<
string2$ = "pears;, " + chr$(34) + "apples ; " + chr$(34) + " an;d bananas"
commentMarker$ = "; #"
Line 1,273:
next i
parse$ = Left$(string$, (i - 1))
End Function</
=={{header|Lua}}==
<
s1 = "apples, pears # and bananas"
Line 1,282:
print ( string.match( s1, "[^"..comment_symbols.."]+" ) )
print ( string.match( s2, "[^"..comment_symbols.."]+" ) )</
=={{header|Maple}}==
<
["apples, pears", "apples, pears"]</
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
apples, pears ; and bananas";
b = StringReplace[a, RegularExpression["[ ]+[#;].+[\n]"] -> "\n"];
StringReplace[b, RegularExpression["[ ]+[#;].+$"] -> ""] // FullForm</
{{out}}
<pre>"apples, pears\napples, pears"</pre>
=={{header|MATLAB}} / {{header|Octave}}==
<
e = min([find(line=='#',1),find(line==';',1)]);
if ~isempty(e)
Line 1,305:
end;
end;
</syntaxhighlight>
Output:
<pre>>> stripcomment('apples, pears # and bananas\n')
Line 1,313:
=={{header|MiniScript}}==
<
comment = test.indexOf("#")
if comment == null then comment = test.indexOf(";")
Line 1,326:
print strip("This is a semicolon test ; a comment") + "."
print strip("This is a no comment test ") + "."
</syntaxhighlight>
{{out}}
<pre>
Line 1,335:
=={{header|Nim}}==
<
proc removeComments(line: string; sep: char): string =
Line 1,347:
echo "Stripped: “$#”" % Str1.removeComments('#')
echo "Original: “$#”" % Str2
echo "Stripped: “$#”" % Str2.removeComments(';')</
{{out}}
Line 1,356:
=={{header|Objeck}}==
<
class StripComments {
Line 1,384:
};
}
}</
=={{header|OCaml}}==
<
let len = String.length str in
let rec aux print i =
Line 1,406:
strip_comments "apples, pears # and bananas\n";
strip_comments "apples, pears ; and bananas\n";
;;</
or with an imperative style:
<
let print = ref true in
String.iter (function
| ';' | '#' -> print := false
| '\n' -> print_char '\n'; print := true
| c -> if !print then print_char c)</
=={{header|Oforth}}==
<
| firstMarker |
markers map(#[ s indexOf ]) reduce(#min) ->firstMarker
s firstMarker ifNotNull: [ left(firstMarker 1 - ) ] strip ;</
{{out}}
Line 1,437:
=={{header|Perl}}==
<
{
s/[#;].*$//s; # remove comment
Line 1,443:
s/\s+$//; # remove trailing whitespace
print
}</
=={{header|Phix}}==
Added a couple of things that can go wrong with something nowhere near sufficiently smart or for that matter language-specific enough.<br>
A line comment inside a block comment (eg " /* left -- right */") could also be very dodgy, and perhaps vice versa.
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">strip_comments</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">sequence</span> <span style="color: #000000;">comments</span><span style="color: #0000FF;">={</span><span style="color: #008000;">"#"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">";"</span><span style="color: #0000FF;">})</span>
Line 1,467:
<span style="color: #0000FF;">?</span><span style="color: #000000;">strip_comments</span><span style="color: #0000FF;">(</span><span style="color: #008000;">" WS_CAPTION = #00C00000, -- = WS_BORDER+WS_DLGFRAME"</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"--"</span><span style="color: #0000FF;">})</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">strip_comments</span><span style="color: #0000FF;">(</span><span style="color: #008000;">" title = \"--Title--\""</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"--"</span><span style="color: #0000FF;">})</span>
<!--</
{{out}}
<pre>
Line 1,479:
=={{header|PicoLisp}}==
<
(prinl (car (split (chop Str) "#" ";"))) )</
Output:
<pre>
Line 1,488:
=={{header|PL/I}}==
<
if k = 0 then put skip list (text);
else put skip list (substr(text, 1, k-1));</
=={{header|Prolog}}==
{{works with|SWI Prolog}}
This version is implemented as a state automata to strip multiple lines of comments.
<
stripcomment([A|AL],[A|BL],a) :- \+ A=0';, \+ A=0'# , \+ A=10, \+ A=13 , stripcomment(AL,BL,a).
stripcomment([A|AL], BL ,a) :- ( A=0';; A=0'#), \+ A=10, \+ A=13 , stripcomment(AL,BL,b).
Line 1,505:
apples, pears # and bananas",
stripcomment(In,Out),
format("~s~n",[Out]).</
Output:
<pre>
Line 1,513:
</pre>
This version uses prolog's pattern matching with two append/3 to strip 1 line.
<
At the query console:
<pre>
Line 1,525:
=={{header|PureBasic}}==
<
Protected result$=Str$, l, l1, l2
l1 =FindString(Str$,"#",1)
Line 1,541:
EndIf
ProcedureReturn result$
EndProcedure</
Implementation
<
#instring2 ="apples, pears ; and bananas"
PrintN(Strip_comments(#instring1))
PrintN(Strip_comments(#instring2))</
Output:<pre>
apples, pears
Line 1,555:
=={{header|Python}}==
===Procedural===
<
for s in sep:
i = line.find(s)
Line 1,565:
print remove_comments('apples ; pears # and bananas', ';#')
print remove_comments('apples ; pears # and bananas', '!')
</syntaxhighlight>
===Regular expressions===
You could also use a regular expression
<
m = re.match(r'^([^#]*)#(.*)$', line)
if m: # The line contains a hash / comment
line = m.group(1)
</syntaxhighlight>
===Functional===
Line 1,581:
which is defined over strings as well as lists.
{{Works with|Python|3.7}}
<
from itertools import takewhile
Line 1,609:
'''
)
)</
{{Out}}
<pre>apples, pears
Line 1,617:
This is most cleanly accomplished using the <code>stringr</code> package.
<
{
if(!require(stringr)) stop("you need to install the stringr package")
str_trim(str_split_fixed(str, "#|;", 2)[, 1])
}</
Example usage:
<
"apples, pears # and bananas", # the requested hash test
"apples, pears ; and bananas", # the requested semicolon test
Line 1,631:
" apples, pears # and bananas" # with preceding spaces
)
strip_comments(x)</
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#lang at-exp racket
Line 1,656:
(strip-comments2 text) ; -> "apples, pears\napples, pears"
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
=={{header|Red}}==
Red has an embedded parse engine called Parse.
For more info on the Parse dialect. http://www.red-lang.org/2013/11/041-introducing-parse.html.
<syntaxhighlight lang="red">
>> parse s: "apples, pears ; and bananas" [to [any space ";"] remove thru end]
== true
>> s
== "apples, pears"
</syntaxhighlight>
But you can also use simple series operations to find where something occurs, clear from that position, and trim leading and trailing spaces.
<syntaxhighlight lang="red">
s: "apples, pears ; and bananas"
dlms: charset "#;"
Line 1,684:
trim head clear find s dlms
== "apples, pears"
</syntaxhighlight>
=={{header|REXX}}==
Line 1,695:
<br>The fourth subroutine is similar to the third version but more idiomatic.
<br><br>All four subroutines trim leading ''and'' trailing blanks after stripping the "comments".
<
old1= ' apples, pears # and bananas' ; say ' old ───►'old1"◄───"
new1= stripCom1(old1) ; say ' 1st version new ───►'new1"◄───"
Line 1,735:
if p\==0 then x=left(x,p-1) /*shorten the X string by one character*/
end /*k*/ /* [↑] If p==0, then char wasn't found*/
return strip(x) /*return the stripped shortened string.*/</
'''output'''
<pre>
Line 1,752:
===version 2===
<
Call stripd ' apples, pears and bananas'
Exit
Line 1,765:
Say '>'old'<'
Say '>'new'<'
Return</
=={{header|Ring}}==
<
aList = 'apples, pears # and bananas'
see aList + nl
Line 1,782:
if nr > 0 cList = substr(bList,1,nr-1) ok
return cList
</syntaxhighlight>
=={{header|Ruby}}==
<
def strip_comment( markers = ['#',';'] )
re = Regexp.union( markers ) # construct a regular expression which will match any of the markers
Line 1,803:
p str.strip_comment('and')
p " \t \n ;".strip_comment
p "".strip_comment</
{{out}}
<pre>
Line 1,815:
=={{header|Rust}}==
<
input
.find(markers)
Line 1,827:
println!("{:?}", strip_comment("apples, pears ; and bananas", &['#', ';']));
println!("{:?}", strip_comment("apples, pears and bananas ", &['#', ';']));
}</
{{out}}
<pre>
Line 1,836:
=={{header|Scala}}==
<
def stripComments1(s:String, markers:String =";#")=s takeWhile (!markers.contains(_)) trim
Line 1,858:
print("apples, pears ; and bananas")
}
}</
Output:
<pre>'apples, pears # and bananas' =>
Line 1,869:
=={{header|Scheme}}==
{{works with|Guile}}
<
(define (strip-comments s)
Line 1,876:
(display (strip-comments "apples, pears # and bananas"))(newline)
(display (strip-comments "apples, pears ; and bananas"))(newline)</
Output:<pre>apples, pears
apples, pears</pre>
=={{header|sed}}==
<
# Strip comments
echo "$1" | sed 's/ *[#;].*$//g' | sed 's/^ *//'</
=={{header|Seed7}}==
<
const func string: stripComment (in string: line) is func
Line 1,916:
writeln(stripComment(line));
end for;
end func;</
Output:
Line 1,928:
=={{header|Sidef}}==
<
(s - %r'[#;].*').strip;
}
Line 1,936:
" apples, pears "].each { |s|
say strip_comment(s).dump;
};</
{{out}}
<pre>
Line 1,946:
=={{header|Standard ML}}==
Strips comments and trailing spaces.
<
let
val notMarker = fn #"#" => false | #";" => false | _ => true
Line 1,952:
in
string o dropr Char.isSpace o takel notMarker o full
end</
=={{header|Tcl}}==
<
# Switch the RE engine into line-respecting mode instead of the default whole-string mode
regsub -all -line "\[$commentChars\].*$" $inputString "" commentStripped
# Now strip the whitespace
regsub -all -line {^[ \t\r]*(.*\S)?[ \t\r]*$} $commentStripped {\1}
}</
Demonstration:
<
set input "apples, pears # and bananas
apples, pears ; and bananas"
# Do the stripping
puts [stripLineComments $input]</
Output:
<pre>
Line 1,973:
</pre>
The above code has one issue though; it's notion of a set of characters is very much that of the RE engine. That's possibly desirable, but to handle ''any'' sequence of characters as a set of separators requires a bit more cleverness.
<
# Convert the character set into a transformation
foreach c [split $commentChars ""] {lappend map $c "\uFFFF"}; # *very* rare character!
Line 1,980:
# Now strip the whitespace
regsub -all -line {^[ \t\r]*(.*\S)?[ \t\r]*$} $commentStripped {\1}
}</
Output in the example is the same as above.
=={{header|TUSCRIPT}}==
<
strngcomment=*
DATA apples, pears # and bananas
Line 1,994:
x=SPLIT (s,comment_char,string,comment)
PRINT string
ENDLOOP</
Output:
<pre>
Line 2,005:
{{works with|pdksh}}
Adapted from the Advanced Bash-Scripting Guide, section 10.1 [http://tldp.org/LDP/abs/html/string-manipulation.html Manipulating Strings].
<
bash$ b='apples, pears # and bananas'
bash$ echo ${a%%;*}
Line 2,011:
bash$ echo ${b%%#*}
apples, pears
bash$</
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
Function strip_comments(s,char)
If InStr(1,s,char) > 0 Then
Line 2,026:
WScript.StdOut.WriteLine strip_comments("apples, pears # and bananas","#")
WScript.StdOut.WriteLine strip_comments("apples, pears ; and bananas",";")
</syntaxhighlight>
=={{header|Vlang}}==
<
fn main() {
Line 2,048:
}
return source
}</
{{out}}
Line 2,062:
=={{header|Wren}}==
This is based on what the post 29th March, 2011 requirements appear to be.
<
var stripComments = Fn.new { |s|
Line 2,081:
var t = stripComments.call(s)
System.print("'%(s)' -> '%(t)'")
}</
{{out}}
Line 2,092:
=={{header|XProfan}}==
Delimiter in string "#" or ";" will be ignored. Good for INI files.
<
Proc Min
Declare int PC, i, float e, t
Line 2,178:
waitkey
end</
Output:
<pre>
Line 2,188:
=={{header|zkl}}==
<
if (Void!=(n:=text.find(c))) text=text[0,n];
text.strip() // remove leading and trailing white space
Line 2,195:
foreach c in (vm.arglist[1,*]){ text=strip(text,c) }
text
}</
Or, if you want the all-in-one stripper:
<
vm.arglist[1,*].reduce('wrap(text,c){
if (Void!=(n:=text.find(c))) text[0,n] else text
},text)
.strip()
}</
<
String(">", stripper(" apples, pears ; and # bananas","#",";"), "<").println();</
{{out}}
<pre>
|