Strip control codes and extended characters from a string: Difference between revisions
Content deleted Content added
add BQN |
Thundergnat (talk | contribs) m syntax highlighting fixup automation |
||
Line 22:
{{trans|Python}}
<
R s.filter(i -> Int(i.code) C 32..126).join(‘’)
print(stripped("\ba\u0000b\n\rc\fd\xc3"))</
{{out}}
Line 33:
=={{header|8086 Assembly}}==
<
.stack 1024
.data
Line 104:
int 10h
ret
end start</
{{out}}
Line 113:
=={{header|Action!}}==
<
IF c<32 OR c>124 OR c=96 OR c=123 THEN
RETURN (0)
Line 142:
Strip(src,dst)
PrintF("Stripped string: ""%S""%E",dst)
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Strip_control_codes_and_extended_characters_from_a_string.png Screenshot from Atari 8-bit computer]
Line 152:
=={{header|Ada}}==
<
procedure Strip_ASCII is
Line 187:
Put_Line("Neither_Extended:", Filter(Full, Above => Character'Last)); -- defaults for From and To
end Strip_ASCII;
</syntaxhighlight>
Output:
Line 197:
=={{header|ALGOL 68}}==
<
# assums ASCII is the character set #
PROC strip characters = ( STRING text, BOOL strip extended )STRING:
Line 226:
STRING t = REPR 2 + "abc" + REPR 10 + REPR 160 + "def~" + REPR 127 + REPR 10 + REPR 150 + REPR 152 + "!";
print( ( "<<" + t + ">> - without control characters: <<" + strip characters( t, FALSE ) + ">>", newline ) );
print( ( "<<" + t + ">> - without control or extended characters: <<" + strip characters( t, TRUE ) + ">>", newline ) )</
{{out}}
<pre>
Line 238:
=={{header|Arturo}}==
<
print "with extended characters"
Line 247:
print join select split str 'x ->
and? ascii? x
not? in? to :integer to :char x (0..31)++127</
{{out}}
Line 258:
=={{header|AutoHotkey}}==
{{trans|Python}}
<
Loop Parse, x
if Asc(A_LoopField) > 31 and Asc(A_LoopField) < 128
Line 264:
return r
}
MsgBox % stripped("`ba" Chr(00) "b`n`rc`fd" Chr(0xc3))</
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f STRIP_CONTROL_CODES_AND_EXTENDED_CHARACTERS.AWK
BEGIN {
Line 276:
exit(0)
}
</syntaxhighlight>
<p>output:</p>
<pre>
Line 289:
While DOS does support ''some'' extended characters, they aren't entirely standardized, and shouldn't be relied upon.
<
DECLARE FUNCTION strip2$ (what AS STRING)
Line 326:
NEXT
strip2$ = outP
END FUNCTION</
Output:
Line 336:
=={{header|BBC BASIC}}==
<
PRINT "Original ISO-8859-1 string: " test$ " (length " ; LEN(test$) ")"
test$ = FNstripcontrol(test$)
Line 362:
ENDIF
ENDWHILE
= A$</
Output:
<pre>
Line 373:
Using BQN's character arithmetic and comparison, characters are binned using <code>⍋</code> and removed if they are inside the range.
<
StripCtEx←(1=(@+32‿127)⊸⍋)⊸/</
<
(rand).Deal∘≠⊸⊏
ascii←RP @+↕256
Line 400:
967
≠StripCtEx unicode
95</
=={{header|Bracmat}}==
<
characters and other ilk.\L\D§►↔◄
Rødgrød med fløde"
Line 429:
)
)
& );</
Output:
<pre>Control characters stripped:
Line 447:
A true/false function checks if the character is in the valid range.<br>
<
#include <stdio.h>
#include <string.h>
Line 573:
return 0;
}</
{{out}}
Line 585:
===<tt>apply mask from a table</tt>===
<
#include <stdlib.h>
Line 648:
return 0;
}</
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!"#$%&'()*+,-./0123456789:;<=>?@[\]^_`{|}~</
=={{header|C sharp|C#}}==
Uses the test string from REXX.
<
using System;
using System.Collections.Generic;
Line 697:
}
}
</syntaxhighlight>
Output:
<pre>
Line 706:
=={{header|C++}}==
<
#include <iostream>
#include <algorithm>
Line 748:
std::cout << "string without extended characters: " << no_extended << std::endl ;
return 0 ;
}</
Output:
<PRE>string with all characters: K�O:~���7�5����
Line 758:
=={{header|Clojure}}==
<
(def range-of-chars (apply str (map char (range 256))))
Line 765:
; filter to return String of characters that are between 32 - 126:
(apply str (filter #(<= 32 (int %) 126) range-of-chars))</
=={{header|Common Lisp}}==
Line 786:
=={{header|D}}==
<
S stripChars(S)(S s, bool function(dchar) pure nothrow mustStrip)
Line 804:
writeln(s.stripChars( c => isControl(c) || c == '\u007F' ));
writeln(s.stripChars( c => isControl(c) || c >= '\u007F' ));
}</
{{out}}
<pre> abcédef�
Line 812:
=={{header|Erlang}}==
Exported functions to be used by [[Update_a_configuration_file]]
<syntaxhighlight lang="erlang">
-module( strip_control_codes ).
Line 831:
String_without_cc_nor_ec = lists:filter( fun is_not_control_code_nor_extended_character/1, String ),
io:fwrite( "String without control codes nor extended characters (~p characters): ~s~n", [erlang:length(String_without_cc_nor_ec), String_without_cc_nor_ec] ).
</syntaxhighlight>
{{out}}
<pre>
Line 843:
=={{header|F Sharp|F#}}==
Uses test string from REXX.
<
open System
Line 862:
printfn "Stripped of extended: %s" (stripExtended test)
0//main must return integer, much like in C/C++
</syntaxhighlight>
Output:
<pre>
Line 871:
=={{header|Factor}}==
<syntaxhighlight lang="text">USING: ascii kernel sequences ;
: strip-control-codes ( str -- str' ) [ control? not ] filter ;
: strip-control-codes-and-extended ( str -- str' )
strip-control-codes [ ascii? ] filter ;</
=={{header|Forth}}==
<
over + over swap over ( buf dst limit src )
do
Line 886:
then
loop
over - ;</
=={{header|Fortran}}==
<
implicit none
Line 943:
write (*,*) strip(string,not_extended)
end program test
</syntaxhighlight>
=={{header|FreeBASIC}}==
<
Function stripControlChars(s As Const String) As String
Line 1,023:
Print
Print "Press any key to quit"
Sleep</
{{out}}
Line 1,039:
=={{header|Frink}}==
<
stripControl[str] := str =~ %s/[\u0000-\u001F\u007f]//g
println[stripExtended[char[0 to 127]]]
println[stripControl[char[0 to 127]]]</
{{out}}
<pre>
Line 1,053:
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=19db658a6c44cfb1f6f887ff53e549bb Click this link to run this code]'''
<
Dim sString As String = "The\t \equick\n \fbrownfox \vcost £125.00 or €145.00 or $160.00 \bto \ncapture ©®"
Dim sStd, sExtend As String
Line 1,083:
Return sResult
End</
Output:
<pre>
Line 1,097:
=={{header|Go}}==
Go works for ASCII and non-ASCII systems. The first pair of functions below interpret strings as byte strings, presumably useful for strings consisting of ASCII and 8-bit extended ASCII data. The second pair of functions interpret strings as UTF-8.
<
import (
Line 1,186:
fmt.Println("\nas decomposed and stripped Unicode:")
fmt.Println(stripCtlAndExtFromUnicode(src))
}</
Output: (varies with display configuration)
<pre>
Line 1,211:
=={{header|Groovy}}==
<
def stripControlAndExtended = { it.replaceAll(/[^\p{Print}]/, '') }</
Test:
<
def textMinusControl = text.findAll { int v = (char)it; v > 31 && v != 127 }.join('')
def textMinusControlAndExtended = textMinusControl.findAll {((char)it) < 128 }.join('')
assert stripControl(text) == textMinusControl
assert stripControlAndExtended(text) == textMinusControlAndExtended</
=={{header|Haskell}}==
<
strip, strip2 :: String -> String
Line 1,233:
main =
(putStrLn . unlines) $
[strip, strip2] <*> ["alphabetic 字母 with some less parochial parts"]</
{{Out}}
<pre>alphabetic with some less parochial parts
Line 1,240:
=={{header|Icon}} and {{header|Unicon}}==
We'll use ''deletec'' to remove unwanted characters (2nd argument) from a string (1st argument). The procedure below coerces types back and forth between string and cset. The character set of unwanted characters is the difference of all ASCII characters and the ASCII characters from 33 to 126.
<
write(image(deletec(&ascii,&ascii--(&ascii)[33:127])))
end
link strings
</syntaxhighlight>
{{libheader|Icon Programming Library}}
Line 1,250:
The IPL procedure ''deletec'' is equivalent to this:
<
result := ""
s ? {
Line 1,256:
return result ||:= tab(0)
}
end</
Line 1,263:
=={{header|J}}==
'''Solution:'''
<
stripControlExtCodes=: ([ -. -.)&(32}.127{.a.)</
'''Usage:'''
<
#mystring NB. length of string
256
Line 1,280:
95
stripControlExtCodes myunicodestring
k}w:]U3xEh9"GZdr/#^B.Sn%\uFOo[(`t2-J6*IA=Vf&N;lQ8,${XLz5?D0~s)'Y7Kq|ip4<WRCaM!b@cgv_T +mH>1ejPy</
Generally speaking, <code>([-.-.)</code> gives us the contents from the sequence on the left, restricted to only the items which appear in the sequence on the right.
Line 1,288:
=={{header|Java}}==
{{works with|Java|8+}}
<
public class StripControlCodes {
Line 1,302:
StringBuilder::appendCodePoint, StringBuilder::append).toString();
}
}</
<pre> abcédef
abcdef</pre>
Line 1,310:
===ES 5===
<
// s -> s
Line 1,323:
return strip(strTest);
})("\ba\x00b\n\rc\fd\xc3");</
{{Out}}
<
=={{header|jq}}==
{{works with|jq|1.4}}
<
explode | map(select(. > 31 and . != 127)) | implode;
def strip_extended_characters:
explode | map(select(31 < . and . < 127)) | implode;</
'''Example''':
<
"string | strip_control_codes\n => \(string | strip_control_codes)",
"string | strip_extended_characters\n => \(string | strip_extended_characters)"</
{{out}}
<
string | strip_control_codes
=> string of ☺☻♥♦⌂, may include control characters such as null() and other ilk.§►↔◄Rødgrød med fløde
string | strip_extended_characters
=> string of , may include control characters such as null() and other ilk.Rdgrd med flde</
=={{header|Julia}}==
<syntaxhighlight lang="julia">
stripc0{T<:String}(a::T) = replace(a, r"[\x00-\x1f\x7f]", "")
stripc0x{T<:String}(a::T) = replace(a, r"[^\x20-\x7e]", "")
Line 1,359:
println("\nWith C0 control characters removed:\n ", stripc0(a))
println("\nWith C0 and extended characters removed:\n ", stripc0x(a))
</syntaxhighlight>
{{out}}
Line 1,375:
=={{header|Kotlin}}==
<
fun String.strip(extendedChars: Boolean = false): String {
Line 1,396:
val u = s.strip(true)
println("String = $u Length = ${u.length}")
}</
{{out}}
Line 1,411:
=={{header|langur}}==
<
writeln "original : ", .str
writeln "without ctrl chars: ", replace(.str, RE/\p{Cc}/, ZLS)
writeln "print ASCII only : ", replace(.str, re/[^ -~]/, ZLS)</
{{out}}
Line 1,423:
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
all$ =""
for i =0 to 255
Line 1,461:
extendedStripped$ =r$
end function
</syntaxhighlight>
=={{header|Lua}}==
<
local s = ""
for i in str:gmatch( "%C+" ) do
Line 1,488:
print( Strip_Control_Codes(q) )
print( Strip_Control_and_Extended_Codes(q) )</
<pre> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€�‚ƒ„…†‡ˆ‰Š‹Œ�Ž��‘’“”•–—˜™š›œ�žŸ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</pre>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
MemberQ[CharacterRange["!","~"]~Join~Characters[FromCharacterCode[Range[128,255]]],#]&]]
stripCtrlExt[x_]:=StringJoin[Select[Characters[x],
MemberQ[CharacterRange["!","~"],#]&]]</
Test:
Line 1,521:
=={{header|MATLAB}} / {{header|Octave}}==
<
str = str(31<str & str<127);
end; </
=={{header|Nim}}==
<
result = ""
for c in str:
Line 1,539:
echo strippedControl "\ba\x00b\n\rc\fdÄ"
echo stripped "\ba\x00b\n\rc\fd\xc3"</
Output:
<pre>abcdÄ
Line 1,546:
=={{header|OCaml}}==
<
let d = int_of_char c in
d < 32 || d = 127
Line 1,578:
print_endline (strip is_control_code s);
print_endline (strip (fun c -> (is_control_code c) || (is_extended_char c)) s);
;;</
=={{header|Pascal}}==
{{works with|Free_Pascal}}
<
function Strip (s: string; control, extended: boolean): string;
Line 1,607:
writeln ('No extnd: ', Strip(test, false, true));
writeln ('ASCII: ', Strip(test, true, true));
end.</
Output:
<pre>% ./StripCharacters
Line 1,620:
=={{header|Peloton}}==
Peloton has a native instruction for removing control codes from a string, SAL, the Low ASCII Strip. From the manual:
<
- - - - - -
Line 1,627:
Assign infix <@ LETVARSALVAR>j|i</@> <@ SAYVAR>j</@>
Assign prepend <@ LETSALVARVAR>k|i</@> <@ SAYVAR>k</@>
Reflexive assign <@ ACTSALVAR>i</@> <@ SAYVAR>i</@></
Peloton also has SAH, High ASCII Strip. Again, from the manual:
<
Strip high ANSI <@ SAYSAHVAR>i</@>
Assign infix <@ LETVARSAHVAR>j|i</@> <@ SAYVAR>j</@>
Assign prepend <@ LETSAHVARVAR>k|i</@> <@ SAYVAR>k</@>
Reflexive assign <@ ACTSAHVAR>i</@> <@ SAYVAR>i</@></
=={{header|Perl}}==
<
use strict ;
Line 1,655:
print "\nWithout extended: " ;
print join( '' , map { chr( $_ ) } @noextended ) ;
print "\n" ;</
Output:
<PRE>before sanitation : �L08&YH�O��n)�:���O�G$���.���"zO���Q�?��
Line 1,667:
to build a new one character-by-character.<br>
I credited Ada solely for the sensible fromch / toch / abovech idea.
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.2"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (param default fixes in pwa/p2js)</span>
Line 1,690:
<span style="color: #000000;">put_line</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"No Control Chars:"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">filter_it</span><span style="color: #0000FF;">(</span><span style="color: #000000;">full</span><span style="color: #0000FF;">))</span> <span style="color: #000080;font-style:italic;">-- default values for fromch, toch, and abovech</span>
<span style="color: #000000;">put_line</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"\" and no Extended:"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">filter_it</span><span style="color: #0000FF;">(</span><span style="color: #000000;">full</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">abovech</span><span style="color: #0000FF;">:=</span><span style="color: #000000;">#FF</span><span style="color: #0000FF;">))</span> <span style="color: #000080;font-style:italic;">-- defaults for fromch and toch</span>
<!--</
{{out}}
(desktop/Phix, in a grubby Windows console)
Line 1,700:
(pwa/p2js)
<pre>
The full string: "
No Control Chars: " abcédef", Length:8
" and no Extended: " abcdef", Length:7
Line 1,709:
=={{header|PicoLisp}}==
Control characters in strings are written with a hat (^) in PicoLisp. ^? is the DEL character.
<
(pack
(filter
Line 1,720:
(filter
'((C) (> "^?" C "^_"))
(chop Str) ) ) )</
Test:
<pre>: (char "^?")
Line 1,735:
=={{header|Pike}}==
<
> (string)((array)input-enumerate(32)-enumerate(255-126,1,127));
Result: "p_xx08M]cK<FHgR3\\I.x>)Tm<VgakYddy&P7"</
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
stripper: proc options (main);
declare s character (100) varying;
Line 1,806:
end stripper;
</syntaxhighlight>
Output:
<pre>
Line 1,816:
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
function Remove-Character
{
Line 1,864:
}
}
</syntaxhighlight>
<syntaxhighlight lang="powershell">
$test = "$([char]9)Français."
Line 1,873:
"Extended characters stripped : `"$($test | Remove-Character -Extended)`""
"Control & extended stripped : `"$($test | Remove-Character)`""
</syntaxhighlight>
{{Out}}
<pre>
Line 1,881:
Control & extended stripped : "Franais."
</pre>
<syntaxhighlight lang="powershell">
"Français", "Čeština" | Remove-Character -Extended
</syntaxhighlight>
{{Out}}
<pre>
Line 1,891:
=={{header|PureBasic}}==
<
Protected i, *ptrChar.Character, length = Len(source), result.s
*ptrChar = @source
Line 1,928:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</
Sample output:
<pre>»╫=┐C─≡G(═ç╤â√╝÷╔¬ÿ▌x è4∞|)ï└⌐ƒ9²òτ┌ºáj)▓<~-vPÿφQ╨ù¿╖îFh"[ü╗dÉ₧q#óé├p╫■
Line 1,935:
=={{header|Python}}==
<
print(stripped("\ba\x00b\n\rc\fd\xc3"))</
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#lang racket
;; Works on both strings (Unicode) and byte strings (raw/ASCII)
Line 1,948:
(define (strip-controls-and-extended str)
(regexp-replace* #rx"[^\040-\176]+" str ""))
</syntaxhighlight>
=={{header|Raku}}==
Line 1,954:
{{works with|Rakudo|2018.03}}
<syntaxhighlight lang="raku"
say $str;
say $str.subst(/<:Cc>/, '', :g); # unicode property: control character
say $str.subst(/<-[\ ..~]>/, '', :g);</
<pre>kşaNĹĭŗ�|Ęw���"ÄlĄWł8iCƁę��Ż�¬�5ĎĶ'óü¸'ÍŸ;ŢƐ¦�´ŷQċűÒŴ$ÃŅ�Đįð+=ĥƂ+Ōĭħ¼ŕc¤H~ìïēÕ
kşaNĹĭŗ|Ęw"ÄlĄWł8iCƁ꯬5ĎĶ'óü¸'ÍŸ;ŢƐ¦´ŷQċűÒŴ$ÃŅĐįð+=ĥƂ+Ōĭħ¼ŕc¤H~ìïēÕ
Line 1,967:
===idiomatic version===
This REXX version processes each character in an idiomatic way (if it's a wanted character, then keep it).
<
z= 'string of ☺☻♥♦⌂, may include control characters and other ♫☼§►↔◄░▒▓█┌┴┐±÷²¬└┬┘ilk.'
@=' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
Line 1,976:
say 'old = »»»'z"«««" /*add ««fence»» before & after old text*/
say 'new = »»»'$"«««" /* " " " " " new " */</
{{out|output}}
<pre>
Line 1,989:
Because there are (or should be) fewer unwanted characters than wanted characters, this version is faster.
<
x= 'string of ☺☻♥♦⌂, may include control characters and other ♫☼§►↔◄░▒▓█┌┴┐±÷²¬└┬┘ilk.'
@=' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghij' || ,
Line 1,999:
say 'old = »»»' || x || "«««" /*add ««fence»» before & after old text*/
say 'new = »»»' || $ || "«««" /* " " " " " new " */</
{{out|output|text= is identical to the 1<sup>st</sup> REXX version.}} <br><br>
=={{header|Ring}}==
<
s = char(31) + "abc" + char(13) + "def" + char(11) + "ghi" + char(10)
see strip(s) + nl
Line 2,016:
next
return strip
</syntaxhighlight>
=={{header|Ruby}}==
<
def strip_control_characters()
chars.each_with_object("") do |char, str|
Line 2,035:
p s = "\ba\x00b\n\rc\fd\xc3\x7ffoo"
p s.strip_control_characters
p s.strip_control_and_extended_characters</
{{out}}
Line 2,043:
=={{header|Run BASIC}}==
<
print strip$(s$)
Line 2,063:
end if
next i
END FUNCTION</
<pre>
input : chr$(31)+"abc"+chr$(13)+"def"+chr$(11)+"ghi"+chr$(10)
Line 2,070:
=={{header|Scala}}==
===ASCII: Using StringOps Class===
<
val extendedCode : (Char) => Boolean = (c:Char) => (c <= 32 || c > 127)
Line 2,081:
println( "ctrl and extended filtered out: \n\n" +
teststring.filterNot(controlCode).filterNot(extendedCode) + "\n" )</
{{out}}
<pre>ctrl filtered out:
Line 2,097:
===Unicode: Using Regular Expressions===
<syntaxhighlight lang="scala">//
// A Unicode test string
//
Line 2,116:
val htmlNoExtCode = for( i <- sNoExtCode.indices ) yield
"&#" + sNoExtCode(i).toInt + ";" + (if( (i+1) % 10 == 0 ) "\n" else "")
println( "ctrl and extended filtered out: <br/><br/>\n\n" + htmlNoExtCode.mkString + "<br/><br/>\n" )</
{{out}}
<pre>ctrl filtered out:
Line 2,156:
Unicode characters with UTF-8 encoding to the console.
<
include "utf8.s7i";
Line 2,206:
writeln("Stripped of control codes and extended characters:");
writeln(stripControlAndExtended(src));
end func;</
Output:
Line 2,221:
=={{header|Sidef}}==
<
var letters = str.chars.map{.ord}
Line 2,230:
var noextended = nocontrols.grep{ _ < 127 }
say noextended.map{.chr}.join.dump</
{{out}}
<pre>
Line 2,239:
=={{header|Standard ML}}==
<
val stripCntrl = concat o String.tokens Char.isCntrl
(* string -> string *)
val stripCntrlAndExt = concat o String.tokens (not o Char.isPrint)</
=={{header|Tcl}}==
<
regsub -all {[\u0000-\u001f\u007f]+} $str ""
}
proc stripCC str {
regsub -all {[^\u0020-\u007e]+} $str ""
}</
=={{header|TI-83 BASIC}}==
Line 2,258:
The following "normal characters" do exist, but can't be typed on the calculator and a hex editor must be used to enter them:
<syntaxhighlight lang
The double quote character (ASCII decimal 34) can be entered, but cannot be escaped and thus cannot be stored to strings without the use of hex editors. The following program will remove double quotes from the input string if they were hacked in simply because having one stored to the "check" string is syntactically invalid.
Line 2,264:
So, in sum, you have to hack the calculator to enter in this program, but once it's entered you can transfer it to unhacked calculators and it will work.
<
:Input ">",Str1
:":"+Str1+":"→Str1
Line 2,272:
:End
:sub(Str1,2,length(Str1)-1)→Str1
:Pause Str1</
=={{header|TXR}}==
Line 2,278:
{{trans|Racket}}
<
(regsub #/[\x0-\x1F\x7F]+/ "" str))
(defun strip-controls-and-extended (str)
(regsub #/[^\x20-\x7F]+/ "" str))</
=={{header|VBScript}}==
Derived from the BASIC version.
<syntaxhighlight lang="vb">
Function StripCtrlCodes(s)
tmp = ""
Line 2,313:
WScript.StdOut.Write "ab�cd�ef�gh�ij†klð€" & " = " & StripCtrlCodesExtChrs("ab�cd�ef�gh�ij†klð€")
WScript.StdOut.WriteLine
</syntaxhighlight>
{{Out}}
Line 2,323:
=={{header|Vlang}}==
{{trans|AutoHotkey}}
<
println(stripped("\ba\x00b\n\rc\fd\xc3"))
}
Line 2,331:
for value in source {if value > 31 && value < 128 {result += value.ascii_str()}}
return result
}</
{{Out}}
Line 2,340:
=={{header|Wren}}==
{{libheader|Wren-pattern}}
<
var s = "\t\n\r\x01\0\fabc\v\v\b\a\x1f\x7f🌇Páez😃É"
Line 2,353:
r = p.replaceAll(s, "")
System.print("%(r) -> length %(r.count)")
</syntaxhighlight>
{{out}}
Line 2,362:
=={{header|XPL0}}==
<
string 0; \use zero-terminated string convention
Line 2,390:
Strip(String, true);
Text(0, String); CrLf(0);
]</
Output:
Line 2,402:
=={{header|zkl}}==
ASCII
<
var extdChars=[127..255].pump(String,"toChar");
Line 2,410:
(test-extdChars).println("<< no extended chars");
(test-extdChars-ctlCodes).println("<< text");
</syntaxhighlight>
{{out}}
<pre>
|