Strip comments from a string: Difference between revisions

(Added Rust example.)
Line 1,117:
>> stripcomment('apples, pears ; and bananas\n')
ans = apples, pears</pre>
 
=={{header|MiniScript}}==
<lang MiniScript>strip = function(test)
comment = test.indexOf("#")
if comment == null then comment = test.indexOf(";")
if comment then test = test[:comment]
while test[-1] == " "
test = test - " "
end while
return test
end function
 
print strip("This is a hash test # a comment") + "."
print strip("This is a semicolon test ; a comment") + "."
print strip("This is a no comment test ") + "."
</lang>
{{out}}
<pre>
This is a hash test.
This is a semicolon test.
This is a no comment test.
</pre>
 
=={{header|Nim}}==