97 lines
5 KiB
Text
97 lines
5 KiB
Text
Determine if a character string is ''squeezable''.
|
|
|
|
And if so, squeeze the string (by removing any number of
|
|
a ''specified'' ''immediately repeated'' character).
|
|
|
|
|
|
This task is very similar to the task '''Determine if a character string is collapsible''' except
|
|
that only a specified character is ''squeezed'' instead of any character that is ''immediately repeated''.
|
|
|
|
|
|
If a character string has a specified ''immediately repeated'' character(s), the repeated characters are to be
|
|
deleted (removed), but not the primary (1<sup>st</sup>) character(s).
|
|
|
|
|
|
A specified ''immediately repeated'' character is any specified character that is <u>immediately</u>
|
|
followed by an identical character (or characters). Another word choice could've been ''duplicated
|
|
character'', but that might have ruled out (to some readers) triplicated characters ··· or more.
|
|
|
|
|
|
{This Rosetta Code task was inspired by a newly introduced (as of around
|
|
November 2019) '''PL/I''' BIF: '''squeeze'''.}
|
|
|
|
|
|
;Examples:
|
|
In the following character string with a specified ''immediately repeated'' character of '''e''':
|
|
|
|
|
|
<big><big> The better the 4-whe<u>e</u>l drive, the further you'll be from help when ya get stuck! </big></big>
|
|
|
|
|
|
Only the 2<sup>nd</sup> '''e''' is an specified repeated character, indicated by an underscore
|
|
(above), even though they (the characters) appear elsewhere in the character string.
|
|
|
|
|
|
|
|
So, after ''squeezing'' the string, the result would be:
|
|
|
|
<big><big> The better the 4-whel drive, the further you'll be from help when ya get stuck! </big></big>
|
|
|
|
|
|
|
|
|
|
Another example:
|
|
In the following character string, using a specified immediately repeated character '''s''':
|
|
|
|
<big><big> headmistres<u>ss</u>hip </big></big>
|
|
|
|
|
|
The "squeezed" string would be:
|
|
|
|
<big><big> headmistreship </big></big>
|
|
|
|
|
|
|
|
;Task:
|
|
Write a subroutine/function/procedure/routine··· to locate a ''specified immediately repeated'' character
|
|
and ''squeeze'' (delete) them from the character string. The
|
|
character string can be processed from either direction.
|
|
|
|
|
|
Show all output here, on this page:
|
|
:* the specified repeated character (to be searched for and possibly ''squeezed''):
|
|
:* the original string and its length
|
|
:* the resultant string and its length
|
|
:* the above strings should be "bracketed" with '''<<<''' and '''>>>''' (to delineate blanks)
|
|
;* «««Guillemets may be used instead for "bracketing" for the more artistic programmers, shown used here»»»
|
|
<!-- Guillemots shouldn't be used as they stink. !-->
|
|
|
|
|
|
Use (at least) the following five strings, all strings are length seventy-two (characters, including blanks), except
|
|
the 1<sup>st</sup> string:
|
|
|
|
immediately
|
|
string repeated
|
|
number character
|
|
( ↓ a blank, a minus, a seven, a period)
|
|
╔╗
|
|
1 ║╚═══════════════════════════════════════════════════════════════════════╗ ' ' ◄■■■■■■ a null string (length zero)
|
|
2 ║"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ║ '-'
|
|
3 ║..1111111111111111111111111111111111111111111111111111111111111117777888║ '7'
|
|
4 ║I never give 'em hell, I just tell the truth, and they think it's hell. ║ '.'
|
|
5 ║ --- Harry S Truman ║ (below) ◄■■■■■■ has many repeated blanks
|
|
╚════════════════════════════════════════════════════════════════════════╝ ↑
|
|
│
|
|
│
|
|
For the 5<sup>th</sup> string (Truman's signature line), use each of these specified immediately repeated characters:
|
|
• a blank
|
|
• a minus
|
|
• a lowercase '''r'''
|
|
|
|
|
|
Note: there should be seven results shown, one each for the 1<sup>st</sup> four strings, and three results for
|
|
the 5<sup>th</sup> string.
|
|
|
|
{{Template:Strings}}
|
|
<br><br>
|
|
|