2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,7 +1,15 @@
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results:
The task is to demonstrate how to remove the first and last characters from a string.
The solution should demonstrate how to obtain the following results:
* String with first character removed
* String with last character removed
* String with both the first and last characters removed
If the program uses UTF-8 or UTF-16, it must work on any valid Unicode code point, whether in the Basic Multilingual Plane or above it. The program must reference logical characters (code points), not 8-bit code units for UTF-8 or 16-bit code units for UTF-16. Programs for other encodings (such as 8-bit ASCII, or EUC-JP) are not required to handle all Unicode characters.
<br>
If the program uses UTF-8 or UTF-16, it must work on any valid Unicode code point, whether in the Basic Multilingual Plane or above it.
The program must reference logical characters (code points), not 8-bit code units for UTF-8 or 16-bit code units for UTF-16.
Programs for other encodings (such as 8-bit ASCII, or EUC-JP) are not required to handle all Unicode characters.
<br><br>

View file

@ -1,13 +1,11 @@
/*REXX program demonstrates removal of 1st/last/1st&last chars from a string. */
/*REXX program demonstrates removal of 1st/last/1st-and-last characters from a string.*/
@ = 'abcdefghijk'
say ' the original string =' @
say 'string first character removed =' substr(@,2)
say 'string last character removed =' left(@,length(@)-1)
say 'string first & last character removed =' substr(@,2,length(@)-2)
/*stick a fork in it, we're all done. */
/* ╔═══════════════════════════════════════════════════════╗
However, the original string may be null or exactly
one byte in length which will cause the BIFs to
fail because of either zero or a negative length.
*/
say 'string first character removed =' substr(@, 2)
say 'string last character removed =' left(@, length(@) -1)
say 'string first & last character removed =' substr(@, 2, length(@) -2)
/*stick a fork in it, we're all done. */
/* ╔═══════════════════════════════════════════════════════════════════════════════╗
However, the original string may be null or exactly one byte in length which
will cause the BIFs to fail because of either zero or a negative length.
*/

View file

@ -1,15 +1,15 @@
/*REXX program demonstrates removal of 1st/last/1st&last chars from a string. */
/*REXX program demonstrates removal of 1st/last/1st-and-last characters from a string.*/
@ = 'abcdefghijk'
say ' the original string =' @
say 'string first character removed =' substr(@,2)
say 'string last character removed =' left(@,max(0,length(@)-1))
say 'string first & last character removed =' substr(@,2,max(0,length(@)-2))
exit /*stick a fork in it, we're all done. */
say 'string first character removed =' substr(@, 2)
say 'string last character removed =' left(@, max(0, length(@) -1))
say 'string first & last character removed =' substr(@, 2, max(0, length(@) -2))
exit /*stick a fork in it, we're all done. */
/* [↓] an easier to read version using a length variable.*/
/* [↓] an easier to read version using a length variable.*/
@ = 'abcdefghijk'
L=length(@)
say ' the original string =' @
say 'string first character removed =' substr(@,2)
say 'string last character removed =' left(@,max(0,L-1))
say 'string first & last character removed =' substr(@,2,max(0,L-2))
say 'string first character removed =' substr(@, 2)
say 'string last character removed =' left(@, max(0, L-1) )
say 'string first & last character removed =' substr(@, 2, max(0, L-2) )

View file

@ -1,16 +1,15 @@
/*REXX program demonstrates removal of 1st/last/1st&last chars from a string. */
/*REXX program demonstrates removal of 1st/last/1st-and-last characters from a string.*/
@ = 'abcdefghijk'
say ' the original string =' @
parse var @ 2 z
say 'string first character removed =' z
m=length(@)-1
m=length(@) - 1
parse var @ z +(m)
say 'string last character removed =' z
n=length(@)-2
n=length(@) - 2
parse var @ 2 z +(n)
if n==0 then z= /*handle special case of a length of 2.*/
say 'string first & last character removed =' z
/*stick a fork in it, we're all done. */
if n==0 then z= /*handle special case of a length of 2.*/
say 'string first & last character removed =' z /*stick a fork in it, we're all done. */

View file

@ -0,0 +1,5 @@
s := 'upraisers'.
Transcript show: 'Top: ', s allButLast; nl.
Transcript show: 'Tail: ', s allButFirst; nl.
Transcript show: 'Without both: ', s allButFirst allButLast; nl.
Transcript show: 'Without both using substring method: ', (s copyFrom: 2 to: s size - 1); nl.

View file

@ -1,4 +1,4 @@
10 PRINT FN f$("knight"): REM strip the first letter
10 PRINT FN f$("knight"): REM strip the first letter. You can also write PRINT "knight"(2 TO)
20 PRINT FN l$("socks"): REM strip the last letter
30 PRINT FN b$("brooms"): REM strip both the first and last letter
100 STOP