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

→‎REXX via translate(): (two) REXX example corrections.
m (added my 2-bits on ASCII & EBCDIC. -- ~~~~)
(→‎REXX via translate(): (two) REXX example corrections.)
 
(4 intermediate revisions by 2 users not shown)
Line 30:
 
:You are correct. Extended codes are not a part of the ascii standard. Also, character 127 is a control character. I have updated the task description to match. It needs a sentence added back in, about extended codes for other standards which incorporate ascii. --[[User:Rdm|Rdm]] 11:01, 25 August 2011 (UTC)
 
== REXX via translate() ==
 
I found this page while searching on how to remove extended ASCII codes using REXX. This helped me to get the answer but the code as presented did not remove the extended characters from even its own example here (tested on Windows and Linux, ooREXX 5.0 and 4.2 respectively).
My solution probably does not work on EBCDIC without modification but as I have no way of testing I can't say what changes would be needed.
<lang rexx>/*REXX program strips all "control codes" from a character string (ASCII or EBCDIC). */
xxx= 'string of ☺☻♥♦⌂, may include control characters and other ilk.♫☼§►↔◄'
above = xrange('80'x,'FF'x) /* extended ASCII characters */
below = xrange('00'x,'1F'x) /* control characters */
yyy = space(translate(xxx,,below)) /* removes control characters */
zzz = space(translate(yyy,,above)) /* removes extended characters */
say 'old = »»»'xxx"«««" /*add ««fence»» before & after old text*/
say 'new = »»»'yyy"«««" /* " " " " " new " */
say 'newer = »»»'zzz"«««" /* " " " " " newer " */
/*stick a fork in it, we're all done. */
</lang>
From this, I cannot see that there is any change with removing the control characters from the string specified. It could be done in one line: <code>yyy = space(translate(translate(xxx,,below),,above))</code>
I post this not as a "better" way but because, at least in the REXX implementation I used, the example code printed the old and new exactly the same with both printing the control characters.
 
--[[User:Abwillis|Abwillis]] 15:47, 20 April 2017 (UTC)
 
<br>
-----
<br>
 
Thanks for finding that error in my REXX programs that I entered &nbsp; (concerning the extended characters). &nbsp; That error has been corrected in both posted REXX programs.
 
On further examination, I also found that the two older REXX versions where still in error &nbsp; (which your above version also has the same problem) &nbsp; in that they were/are also removing multiple (adjacent) blanks, so I rewrote and updated the erroneous two REXX examples.
 
By the way, the error has to do with translating unwanted characters to a blank, and then removing the &nbsp; ''excess'' &nbsp; blanks. <br> But that also removes excess blanks &nbsp; (blanks that are adjacent to another) &nbsp; from the original string. &nbsp; -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 23:02, 22 April 2017 (UTC)