Jump to content

Strip control codes and extended characters from a string: Difference between revisions

Added Wren
m (spelling corrections)
(Added Wren)
Line 2,095:
ab�cd�ef�gh�€ = abcdefgh€
ab�cd�ef�gh�ij†klð€ = abcdefghijkl
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-pattern}}
<lang ecmascript>import "/pattern" for Pattern
 
var s = "\t\n\r\x01\0\fabc\v\v\b\a\x1f\x7f🌇Páez😃É"
 
// strip control codes only
var p = Pattern.new("+1/c")
var r = p.replaceAll(s, "")
System.print("%(r) -> length %(r.count)")
 
// strip extended characters as well
p = Pattern.new("[+1/c|/R]")
r = p.replaceAll(s, "")
System.print("%(r) -> length %(r.count)")
</lang>
 
{{out}}
<pre>
abc🌇Páez😃É -> length 10
abcPez -> length 6
</pre>
 
9,492

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.