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

Content added Content deleted
(Go solution)
Line 213: Line 213:


[[Category:String manipulation]]
[[Category:String manipulation]]
=={{header|Lua}}==
<lang lua>function Strip_Control_Codes( str )
local s = ""
for i in str:gmatch( "%C+" ) do
s = s .. i
end
return s
end

function Strip_Control_and_Extended_Codes( str )
local s = ""
for i = 1, str:len() do
if str:byte(i) >= 32 and str:byte(i) <= 126 then
s = s .. str:sub(i,i)
end
end
return s
end

q = ""
for i = 0, 255 do
q = q .. string.char(i)
end

print( Strip_Control_Codes(q) )
print( Strip_Control_and_Extended_Codes(q) )</lang>
<pre> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</pre>


=={{header|Perl 6}}==
=={{header|Perl 6}}==