Anonymous user
Strip comments from a string: Difference between revisions
Added Rust example.
(→Functional Python: Pylinted and added {works with} tag) |
(Added Rust example.) |
||
Line 1,580:
""
""
</pre>
=={{header|Rust}}==
<lang rust>fn strip_comment<'a>(input: &'a str, markers: &[char]) -> &'a str {
input
.find(markers)
.map(|idx| &input[..idx])
.unwrap_or(input)
.trim()
}
fn main() {
println!("{:?}", strip_comment("apples, pears # and bananas", &['#', ';']));
println!("{:?}", strip_comment("apples, pears ; and bananas", &['#', ';']));
println!("{:?}", strip_comment("apples, pears and bananas ", &['#', ';']));
}</lang>
{{out}}
<pre>
"apples, pears"
"apples, pears"
"apples, pears and bananas"
</pre>
|