Determine if a string is squeezable: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: corrected an input data field in the REXX program and it's corresponding output.) |
(Add Factor) |
||
Line 103: | Line 103: | ||
<br><br> |
<br><br> |
||
=={{header|Factor}}== |
|||
<lang factor>USING: formatting fry io kernel math sbufs sequences strings ; |
|||
IN: rosetta-code.squeeze |
|||
: (squeeze) ( str c -- new-str ) |
|||
[ unclip-slice 1string >sbuf ] dip |
|||
'[ over last over [ _ = ] both? [ drop ] [ suffix! ] if ] |
|||
reduce >string ; |
|||
: squeeze ( str c -- new-str ) |
|||
over empty? [ 2drop "" ] [ (squeeze) ] if ; |
|||
: .str ( str -- ) dup length "«««%s»»» (length %d)\n" printf ; |
|||
: show-squeeze ( str c -- ) |
|||
dup "Specified character: '%c'\n" printf |
|||
[ "Before squeeze: " write drop .str ] |
|||
[ "After squeeze: " write squeeze .str ] 2bi nl ; |
|||
: squeeze-demo ( -- ) |
|||
{ |
|||
"" |
|||
"\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln " |
|||
"..1111111111111111111111111111111111111111111111111111111111111117777888" |
|||
"I never give 'em hell, I just tell the truth, and they think it's hell. " |
|||
} "\0-7." [ show-squeeze ] 2each |
|||
" --- Harry S Truman " |
|||
[ CHAR: space ] [ CHAR: - ] [ CHAR: r ] tri |
|||
[ show-squeeze ] 2tri@ ; |
|||
MAIN: squeeze-demo</lang> |
|||
{{out}} |
|||
<pre> |
|||
Specified character: ' ' |
|||
Before squeeze: «««»»» (length 0) |
|||
After squeeze: «««»»» (length 0) |
|||
Specified character: '-' |
|||
Before squeeze: «««"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln »»» (length 72) |
|||
After squeeze: «««"If I were two-faced, would I be wearing this one?" - Abraham Lincoln »»» (length 70) |
|||
Specified character: '7' |
|||
Before squeeze: «««..1111111111111111111111111111111111111111111111111111111111111117777888»»» (length 72) |
|||
After squeeze: «««..1111111111111111111111111111111111111111111111111111111111111117888»»» (length 69) |
|||
Specified character: '.' |
|||
Before squeeze: «««I never give 'em hell, I just tell the truth, and they think it's hell. »»» (length 72) |
|||
After squeeze: «««I never give 'em hell, I just tell the truth, and they think it's hell. »»» (length 72) |
|||
Specified character: ' ' |
|||
Before squeeze: ««« --- Harry S Truman »»» (length 72) |
|||
After squeeze: ««« --- Harry S Truman »»» (length 20) |
|||
Specified character: '-' |
|||
Before squeeze: ««« --- Harry S Truman »»» (length 72) |
|||
After squeeze: ««« - Harry S Truman »»» (length 70) |
|||
Specified character: 'r' |
|||
Before squeeze: ««« --- Harry S Truman »»» (length 72) |
|||
After squeeze: ««« --- Hary S Truman »»» (length 71) |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |