Family Day update

This commit is contained in:
Ingy döt Net 2020-02-17 23:21:07 -08:00
parent aac6731f2c
commit 9ad63ea473
2442 changed files with 39761 additions and 8255 deletions

View file

@ -3,6 +3,8 @@ Display the words to the 'user', in the simplest manner possible,
separated by a period.
To simplify, you may display a trailing period.
'''''Related tasks:'''''
* [[Tokenize a string with escaping]]
;Related tasks:
*   [[Tokenize a string with escaping]]
*   [[Split a character string based on change of character|split a character string based on change of character]]
<br><br>

View file

@ -1,17 +1,21 @@
with Ada.Text_IO, Ada.Containers.Indefinite_Vectors;
use Ada.Text_IO, Ada.Containers;
with Ada.Text_IO, Ada.Containers.Indefinite_Vectors, Ada.Strings.Fixed, Ada.Strings.Maps;
use Ada.Text_IO, Ada.Containers, Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps;
procedure tokenize is
package String_Vector is new Indefinite_Vectors (Natural,String); use String_Vector;
s : String := "Hello,How,Are,You,Today" & ",";
current : Positive := s'First;
v : Vector;
procedure Tokenize is
package String_Vectors is new Indefinite_Vectors (Positive, String);
use String_Vectors;
Input : String := "Hello,How,Are,You,Today";
Start : Positive := Input'First;
Finish : Natural := 0;
Output : Vector := Empty_Vector;
begin
for i in s'range loop
if s (i) = ',' or i = s'last then
v.append (s (current .. i-1));
current := i + 1;
end if;
while Start <= Input'Last loop
Find_Token (Input, To_Set (','), Start, Outside, Start, Finish);
exit when Start > Finish;
Output.Append (Input (Start .. Finish));
Start := Finish + 1;
end loop;
for s of v loop put(s & "."); end loop;
end tokenize;
for S of Output loop
Put (S & ".");
end loop;
end Tokenize;

View file

@ -2,4 +2,4 @@ import strutils
let text = "Hello,How,Are,You,Today"
let tokens = text.split(',')
echo tokens.join(" ")
echo tokens.join(".")

View file

@ -1,17 +1,13 @@
/*REXX program separates a string of comma-delimited words, and echoes. */
sss = 'Hello,How,Are,You,Today' /*words seperated by commas (,). */
say 'input string =' sss /*display the original string. */
new=sss /*make a copy of the string. */
/* [↓] string NEW is destroyed. */
do items=1 until new=='' /*keep going until NEW is empty.*/
parse var new a.items ',' new /*parse words delinated by comma.*/
end /*items*/ /* [↑] the array is named A. */
say; say 'Words in the string:' /*display a header for the list. */
do j=1 for items /*now, display all the words. */
say a.j || left('.', j\==items) /*append period to word, maybe. */
end /*j*/ /* [↑] don't append "." if last.*/
say 'End-of-list.' /*display a trailer for the list.*/
/*stick a fork in it, we're done.*/
/*REXX program separates a string of comma─delimited words, and echoes them ──► terminal*/
original = 'Hello,How,Are,You,Today' /*some words separated by commas (,). */
say 'The input string:' original /*display original string ──► terminal.*/
new= original /*make a copy of the string. */
do #=1 until new=='' /*keep processing until NEW is empty.*/
parse var new @.# ',' new /*parse words delineated by a comma (,)*/
end /*#*/ /* [↑] the new array is named @. */
say /* NEW is destructively parsed. [↑] */
say center(' Words in the string ', 40, "") /*display a nice header for the list. */
do j=1 for # /*display all the words (one per line),*/
say @.j || left(., j\==#) /*maybe append a period (.) to a word. */
end /*j*/ /* [↑] don't append a period if last. */
say center(' Endoflist ', 40, "") /*display a (EOL) trailer for the list.*/