Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
category:
- Simple
from: http://rosettacode.org/wiki/Tokenize_a_string
note: String manipulation

View file

@ -0,0 +1,10 @@
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word.
Display the words to the 'user', in the simplest manner possible, separated by a period.
To simplify, you may display a trailing period.
{{Template:Strings}}
<br><br>

View file

@ -0,0 +1,3 @@
V text = Hello,How,Are,You,Today
V tokens = text.split(,)
print(tokens.join(.))

View file

@ -0,0 +1,83 @@
* Tokenize a string - 08/06/2018
TOKSTR CSECT
USING TOKSTR,R13 base register
B 72(R15) skip savearea
DC 17F'0' savearea
SAVE (14,12) save previous context
ST R13,4(R15) link backward
ST R15,8(R13) link forward
LR R13,R15 set addressability
MVC N,=A(1) n=1
LA R7,1 i1=1
LA R6,1 i=1
DO WHILE=(C,R6,LE,LENS) do i=1 to length(s);
LA R4,S-1 @s-1
AR R4,R6 +i
MVC C,0(R4) c=substr(s,i,1)
IF CLI,C,EQ,C',' THEN if c=',' then do
BAL R14,TOK call tok
LR R2,R8 i2
SR R2,R7 i2-i1
LA R2,1(R2) i2-i1+1
L R1,N n
SLA R1,1 *2
STH R2,TALEN-2(R1) talen(n)=i2-i1+1
L R2,N n
LA R2,1(R2) n+1
ST R2,N n=n+1
LA R7,1(R6) i1=i+1
ENDIF , endif
LA R6,1(R6) i++
ENDDO , enddo i
BAL R14,TOK call tok
LR R2,R8 i2
SR R2,R7 i2-i1
LA R2,1(R2) i2-i1+1
L R1,N n
SLA R1,1 *2
STH R2,TALEN-2(R1) talen(n)=i2-i1+1
LA R11,PG pgi=@pg
LA R6,1 i=1
DO WHILE=(C,R6,LE,N) do i=1 to n
LR R1,R6 i
SLA R1,1 *2
LH R10,TALEN-2(R1) l=talen(i)
LR R1,R6 i
SLA R1,3 *8
LA R4,TABLE-8(R1) @table(i)
LR R2,R10 l
BCTR R2,0 ~
EX R2,MVCX output table(i) length(l)
AR R11,R10 pgi=pgi+l
IF C,R6,NE,N THEN if i^=n then
MVC 0(1,R11),=C'.' output '.'
LA R11,1(R11) pgi=pgi+1
ENDIF , endif
LA R6,1(R6) i++
ENDDO , enddo i
XPRNT PG,L'PG print
L R13,4(0,R13) restore previous savearea pointer
RETURN (14,12),RC=0 restore registers from calling sav
TOK LR R5,R6 i <--
BCTR R5,0 i-1 |
LR R8,R5 i2=i-1
SR R5,R7 i2-i1
LA R5,1(R5) l=i2-i1+1 source length
L R1,N n
SLA R1,3 *8
LA R2,TABLE-8(R1) @table(n)
LA R4,S-1 @s-1
AR R4,R7 @s+i1-1
LA R3,8 target length
MVCL R2,R4 table(n)=substr(s,i1,i2-i1+1) |
BR R14 End TOK subroutine <--
MVCX MVC 0(0,R11),0(R4) output table(i)
S DC CL80'Hello,How,Are,You,Today' <== input string ==
LENS DC F'23' length(s) <==
TABLE DC 8CL8' ' table(8)
TALEN DC 8H'0' talen(8)
C DS CL1 char
N DS F number of tokens
PG DC CL80' ' buffer
YREGS
END TOKSTR

View file

@ -0,0 +1,48 @@
puts: equ 9
org 100h
jmp demo
;;; Split the string at DE by the character in C.
;;; Store pointers to the beginning of the elements starting at HL
;;; The amount of elements is returned in B.
split: mvi b,0 ; Amount of elements
sloop: mov m,e ; Store pointer at [HL]
inx h
mov m,d
inx h
inr b ; Increment counter
sscan: ldax d ; Get current character
inx d
cpi '$' ; Done?
rz ; Then stop
cmp c ; Place to split?
jnz sscan ; If not, keep going
dcx d
mvi a,'$' ; End the string here
stax d
inx d
jmp sloop ; Next part
;;; Test on the string given in the task
demo: lxi h,parts ; Parts array
lxi d,hello ; String
mvi c,','
call split ; Split the string
lxi h,parts ; Print each part
loop: mov e,m ; Load pointer into DE
inx h
mov d,m
inx h
push h ; Keep the array pointer
push b ; And the counter
mvi c,puts ; Print the string
call 5
lxi d,period ; And a period
mvi c,puts
call 5
pop b ; Restore the counter
pop h ; Restore the array pointer
dcr b ; One fewer string left
jnz loop
ret
period: db '. $'
hello: db 'Hello,How,Are,You,Today$'
parts: equ $

View file

@ -0,0 +1,39 @@
cpu 8086
org 100h
section .text
jmp demo
;;; Split the string at DS:SI on the character in DL.
;;; Store pointers to strings starting at ES:DI.
;;; The amount of strings is returned in CX.
split: xor cx,cx ; Zero out counter
.loop: mov ax,si ; Store pointer to current location
stosw
inc cx ; Increment counter
.scan: lodsb ; Get byte
cmp al,'$' ; End of string?
je .done
cmp al,dl ; Character to split on?
jne .scan
mov [si-1],byte '$' ; Terminate string
jmp .loop
.done: ret
;;; Test on the string given in the task
demo: mov si,hello ; String to split
mov di,parts ; Place to store pointers
mov dl,',' ; Character to split string on
call split
;;; Print the resulting strings, and periods
mov si,parts ; Array of string pointers
print: lodsw ; Load next pointer
mov dx,ax ; Print string using DOS
mov ah,9
int 21h
mov dx,period ; Then print a period
int 21h
loop print ; Loop while there are strings
ret
section .data
period: db '. $'
hello: db 'Hello,How,Are,You,Today$'
section .bss
parts: resw 10

View file

@ -0,0 +1,139 @@
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program strTokenize64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
.equ NBPOSTESECLAT, 20
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szMessFinal: .asciz "Words are : \n"
szString: .asciz "Hello,How,Are,You,Today"
szMessError: .asciz "Error tokenize !!\n"
szCarriageReturn: .asciz "\n"
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
/*******************************************/
/* code section */
/*******************************************/
.text
.global main
main:
ldr x0,qAdrszString // string address
mov x1,',' // separator
bl stTokenize
cmp x0,-1 // error ?
beq 99f
mov x2,x0 // table address
ldr x0,qAdrszMessFinal // display message
bl affichageMess
ldr x4,[x2] // number of areas
add x2,x2,8 // first area
mov x3,0 // loop counter
mov x0,x2
1: // display loop
ldr x0,[x2,x3, lsl 3] // address area
bl affichageMess
ldr x0,qAdrszCarriageReturn // display carriage return
bl affichageMess
add x3,x3,1 // counter + 1
cmp x3,x4 // end ?
blt 1b // no -> loop
b 100f
99: // display error message
ldr x0,qAdrszMessError
bl affichageMess
100: // standard end of the program
mov x0,0 // return code
mov x8,EXIT // request to exit program
svc 0 // perform the system call
qAdrszString: .quad szString
//qAdrszFinalString: .quad szFinalString
qAdrszMessFinal: .quad szMessFinal
qAdrszMessError: .quad szMessError
qAdrszCarriageReturn: .quad szCarriageReturn
/*******************************************************************/
/* Separate string by separator into an array */
/* areas are store on the heap Linux */
/*******************************************************************/
/* x0 contains string address */
/* x1 contains separator character (, or . or : ) */
/* x0 returns table address with first item = number areas */
/* and other items contains pointer of each string */
stTokenize:
stp x1,lr,[sp,-16]! // save registers
mov x16,x0
mov x9,x1 // save separator
mov x14,0
1: // compute length string for place reservation on the heap
ldrb w12,[x0,x14]
cbz x12, 2f
add x14,x14,1
b 1b
2:
ldr x12,qTailleTable
add x15,x12,x14
and x15,x15,0xFFFFFFFFFFFFFFF0
add x15,x15,16 // align word on the heap
// place reservation on the heap
mov x0,0 // heap address
mov x8,BRK // call system linux 'brk'
svc 0 // call system
cmp x0,-1 // error call system
beq 100f
mov x14,x0 // save address heap begin = begin array
add x0,x0,x15 // reserve x15 byte on the heap
mov x8,BRK // call system linux 'brk'
svc 0
cmp x0,-1
beq 100f
// string copy on the heap
add x13,x14,x12 // behind the array
mov x0,x16
mov x1,x13
3: // loop copy string
ldrb w12,[x0],1 // read one byte and increment pointer one byte
strb w12,[x1],1 // store one byte and increment pointer one byte
cbnz x12,3b // end of string ? no -> loop
mov x0,#0
str x0,[x14]
str x13,[x14,8]
mov x12,#1 // areas counter
4: // loop load string character
ldrb w0,[x13]
cbz x0,5f // end string
cmp x0,x9 // separator ?
cinc x13,x13,ne // no -> next location
bne 4b // and loop
strb wzr,[x13] // store zero final of string
add x13,x13,1 // next character
add x12,x12,1 // areas counter + 1
str x13,[x14,x12, lsl #3] // store address area in the table at index x2
b 4b // and loop
5:
str x12,[x14] // store number areas
mov x0,x14 // returns array address
100:
ldp x1,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qTailleTable: .quad 8 * NBPOSTESECLAT
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"

View file

@ -0,0 +1,29 @@
(defun split-at (xs delim)
(if (or (endp xs) (eql (first xs) delim))
(mv nil (rest xs))
(mv-let (before after)
(split-at (rest xs) delim)
(mv (cons (first xs) before) after))))
(defun split (xs delim)
(if (endp xs)
nil
(mv-let (before after)
(split-at xs delim)
(cons before (split after delim)))))
(defun css->strs (css)
(if (endp css)
nil
(cons (coerce (first css) 'string)
(css->strs (rest css)))))
(defun split-str (str delim)
(css->strs (split (coerce str 'list) delim)))
(defun print-with (strs delim)
(if (endp strs)
(cw "~%")
(progn$ (cw (first strs))
(cw (coerce (list delim) 'string))
(print-with (rest strs) delim))))

View file

@ -0,0 +1,49 @@
main:(
OP +:= = (REF FLEX[]STRING in out, STRING item)VOID:(
[LWB in out: UPB in out+1]STRING new;
new[LWB in out: UPB in out]:=in out;
new[UPB new]:=item;
in out := new
);
PROC string split = (REF STRING beetles, STRING substr)[]STRING:(
""" Split beetles where substr is found """;
FLEX[1:0]STRING out;
INT start := 1, pos;
WHILE string in string(substr, pos, beetles[start:]) DO
out +:= STRING(beetles[start:start+pos-2]);
start +:= pos + UPB substr - 1
OD;
IF start > LWB beetles THEN
out +:= STRING(beetles[start:])
FI;
out
);
PROC char split = (REF STRING beetles, STRING chars)[]STRING: (
""" Split beetles where character is found in chars """;
FLEX[1:0]STRING out;
FILE beetlef;
associate(beetlef, beetles); # associate a FILE handle with a STRING #
make term(beetlef, chars); # make term: assign CSV string terminator #
PROC raise logical file end = (REF FILE f)BOOL: except logical file end;
on logical file end(beetlef, raise logical file end);
STRING solo;
DO
getf(beetlef, ($g$, solo));
out+:=solo;
getf(beetlef, ($x$)) # skip CHAR separator #
OD;
except logical file end:
SKIP;
out
);
STRING beetles := "John Lennon, Paul McCartney, George Harrison, Ringo Starr";
printf(($g"."$, string split(beetles, ", "),$l$));
printf(($g"."$, char split(beetles, ", "),$l$))
)

View file

@ -0,0 +1,2 @@
'.',¨ ','()'abc,123,X' ⍝ [1] Do the split: ','(≠⊆⊢)'abc,123,X'; [2] append the periods: '.',⍨¨
abc. 123. X. ⍝ 3 strings (char vectors), each with a period at the end.

View file

@ -0,0 +1,161 @@
/* ARM assembly Raspberry PI */
/* program strTokenize.s */
/* Constantes */
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
.equ NBPOSTESECLAT, 20
/* Initialized data */
.data
szMessFinal: .asciz "Words are : \n"
szString: .asciz "Hello,How,Are,You,Today"
szMessError: .asciz "Error tokenize !!\n"
szCarriageReturn: .asciz "\n"
/* UnInitialized data */
.bss
/* code section */
.text
.global main
main:
ldr r0,iAdrszString @ string address
mov r1,#',' @ separator
bl stTokenize
cmp r0,#-1 @ error ?
beq 99f
mov r2,r0 @ table address
ldr r0,iAdrszMessFinal @ display message
bl affichageMess
ldr r4,[r2] @ number of areas
add r2,#4 @ first area
mov r3,#0 @ loop counter
1: @ display loop
ldr r0,[r2,r3, lsl #2] @ address area
bl affichageMess
ldr r0,iAdrszCarriageReturn @ display carriage return
bl affichageMess
add r3,#1 @ counter + 1
cmp r3,r4 @ end ?
blt 1b @ no -> loop
b 100f
99: @ display error message
ldr r0,iAdrszMessError
bl affichageMess
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
svc 0 @ perform the system call
iAdrszString: .int szString
iAdrszFinalString: .int szFinalString
iAdrszMessFinal: .int szMessFinal
iAdrszMessError: .int szMessError
iAdrszCarriageReturn: .int szCarriageReturn
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {r0,r1,r2,r7,lr} @ save registers
mov r2,#0 @ counter length */
1: @ loop length calculation
ldrb r1,[r0,r2] @ read octet start position + index
cmp r1,#0 @ if 0 its over
addne r2,r2,#1 @ else add 1 in the length
bne 1b @ and loop
@ so here r2 contains the length of the message
mov r1,r0 @ address message in r1
mov r0,#STDOUT @ code to write to the standard output Linux
mov r7, #WRITE @ code call system "write"
svc #0 @ call systeme
pop {r0,r1,r2,r7,lr} @ restaur des 2 registres
bx lr @ return
/*******************************************************************/
/* Separate string by separator into an array */
/* areas are store on the heap Linux */
/*******************************************************************/
/* r0 contains string address */
/* r1 contains separator character (, or . or : ) */
/* r0 returns table address with first item = number areas */
/* and other items contains pointer of each string */
stTokenize:
push {r1-r8,lr} @ save des registres
mov r6,r0
mov r8,r1 @ save separator
bl strLength @ length string for place reservation on the heap
mov r4,r0
ldr r5,iTailleTable
add r5,r0
and r5,#0xFFFFFFFC
add r5,#4 @ align word on the heap
@ place reservation on the heap
mov r0,#0 @ heap address
mov r7, #0x2D @ call system linux 'brk'
svc #0 @ call system
cmp r0,#-1 @ error call system
beq 100f
mov r3,r0 @ save address heap begin
add r0,r5 @ reserve r5 byte on the heap
mov r7, #0x2D @ call system linux 'brk'
svc #0
cmp r0,#-1
beq 100f
@ string copy on the heap
mov r0,r6
mov r1,r3
1: @ loop copy string
ldrb r2,[r0],#1 @ read one byte and increment pointer one byte
strb r2,[r1],#1 @ store one byte and increment pointer one byte
cmp r2,#0 @ end of string ?
bne 1b @ no -> loop
add r4,r3 @ r4 contains address table begin
mov r0,#0
str r0,[r4]
str r3,[r4,#4]
mov r2,#1 @ areas counter
2: @ loop load string character
ldrb r0,[r3]
cmp r0,#0
beq 3f @ end string
cmp r0,r8 @ separator ?
addne r3,#1 @ no -> next location
bne 2b @ and loop
mov r0,#0 @ store zero final of string
strb r0,[r3]
add r3,#1 @ next character
add r2,#1 @ areas counter + 1
str r3,[r4,r2, lsl #2] @ store address area in the table at index r2
b 2b @ and loop
3:
str r2,[r4] @ returns number areas
mov r0,r4
100:
pop {r1-r8,lr}
bx lr
iTailleTable: .int 4 * NBPOSTESECLAT
/***************************************************/
/* calcul size string */
/***************************************************/
/* r0 string address */
/* r0 returns size string */
strLength:
push {r1,r2,lr}
mov r1,#0 @ init counter
1:
ldrb r2,[r0,r1] @ load byte of string index r1
cmp r2,#0 @ end string ?
addne r1,#1 @ no -> +1 counter
bne 1b @ and loop
100:
mov r0,r1
pop {r1,r2,lr}
bx lr

View file

@ -0,0 +1,8 @@
BEGIN {
s = "Hello,How,Are,You,Today"
split(s, arr, ",")
for(i=1; i < length(arr); i++) {
printf arr[i] "."
}
print
}

View file

@ -0,0 +1,5 @@
BEGIN { FS = "," }
{
for(i=1; i <= NF; i++) printf $i ".";
print ""
}

View file

@ -0,0 +1,94 @@
CARD EndProg ;required for ALLOCATE.ACT
INCLUDE "D2:ALLOCATE.ACT" ;from the Action! Tool Kit. You must type 'SET EndProg=*' from the monitor after compiling, but before running this program!
DEFINE PTR="CARD"
BYTE FUNC Split(CHAR ARRAY s CHAR c PTR ARRAY items)
BYTE i,count,start,len
CHAR ARRAY item
IF s(0)=0 THEN RETURN (0) FI
i=1 count=0
WHILE i<s(0)
DO
start=i
WHILE i<=s(0) AND s(i)#c
DO
i==+1
OD
len=i-start
item=Alloc(len+1)
SCopyS(item,s,start,i-1)
items(count)=item
count==+1
i==+1
OD
RETURN (count)
PROC Join(PTR ARRAY items BYTE count CHAR c CHAR ARRAY s)
BYTE i,pos
CHAR POINTER srcPtr,dstPtr
CHAR ARRAY item
s(0)=0
IF count=0 THEN RETURN FI
pos=1
FOR i=0 TO count-1
DO
item=items(i)
srcPtr=item+1
dstPtr=s+pos
MoveBlock(dstPtr,srcPtr,item(0))
pos==+item(0)
IF i<count-1 THEN
s(pos)='.
pos==+1
FI
OD
s(0)=pos-1
RETURN
PROC Clear(PTR ARRAY items BYTE POINTER count)
BYTE i
CHAR ARRAY item
IF count^=0 THEN RETURN FI
FOR i=0 TO count^-1
DO
item=items(i)
Free(item,item(0)+1)
OD
count^=0
RETURN
PROC Main()
CHAR ARRAY s="Hello,How,Are,You,Today"
CHAR ARRAY r(256)
PTR ARRAY items(100)
BYTE i,count
Put(125) PutE() ;clear screen
AllocInit(0)
count=Split(s,',,items)
Join(items,count,'.,r)
PrintF("Input:%E""%S""%E%E",s)
PrintE("Split:")
FOR i=0 TO count-1
DO
PrintF("""%S""",items(i))
IF i<count-1 THEN
Print(", ")
ELSE
PutE() PutE()
FI
OD
PrintF("Join:%E""%S""%E",r)
Clear(items,@count)
RETURN

View file

@ -0,0 +1,6 @@
var hello:String = "Hello,How,Are,You,Today";
var tokens:Array = hello.split(",");
trace(tokens.join("."));
// Or as a one-liner
trace("Hello,How,Are,You,Today".split(",").join("."));

View file

@ -0,0 +1,21 @@
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_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
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 Output loop
Put (S & ".");
end loop;
end Tokenize;

View file

@ -0,0 +1,63 @@
#include <hopper.h>
#proto splitdate(_DATETIME_)
#proto splitnumber(_N_)
#proto split(_S_,_T_)
main:
s="this string will be separated into parts with space token separator"
aS=0,let( aS :=_split(s," "))
{","}toksep // set a new token separator
{"String: ",s}
{"\nArray:\n",aS},
{"\nSize="}size(aS),println // "size" return an array: {dims,#rows,#cols,#pages}
{"\nOriginal number: ",-125.489922},println
w=0,let(w:=_split number(-125.489922) )
{"Integer part: "}[1]get(w) // get first element from array "w"
{"\nDecimal part: "}[2]get(w),println // get second element from array "w"
{"\nDate by DATENOW(TODAY) macro: "},print
dt=0, let( dt :=_splitdate(datenow(TODAY);!puts)) // "!" keep first element from stack
{"\nDate: "}[1]get(dt)
{"\nTime: "}[2]get(dt),println
exit(0)
.locals
splitdate(_DATETIME_)
_SEP_=0,gettoksep,mov(_SEP_) // "gettoksep" return actual token separator
{","}toksep, // set a new token separator
_NEWARRAY_={}
{1},$( _DATETIME_ ),
{2},$( _DATETIME_ ),pushall(_NEWARRAY_)
{_SEP_}toksep // restore ols token separator
{_NEWARRAY_}
back
splitnumber(_X_)
part_int=0,part_dec=0,
{_X_},!trunc,mov(part_int),
minus(part_int), !sign,mul
xtostr,mov(part_dec), part_dec+=2, // "part_dec+=2", delete "0." from "part_dec"
{part_dec}xtonum,mov(part_dec)
_NEWARRAY_={},{part_int,part_dec},pushall(_NEWARRAY_)
{_NEWARRAY_}
back
split(_S_,_T_)
_NEWARRAY_={},_VAR1_=0,_SEP_=0,gettoksep,mov(_SEP_)
{_T_}toksep,totaltoken(_S_),
mov(_VAR1_), // for total tokens
_VAR2_=1, // for real position of tokens into the string
___SPLIT_ITER:
{_VAR2_}$( _S_ ),push(_NEWARRAY_)
++_VAR2_,--_VAR1_
{ _VAR1_ },jnz(___SPLIT_ITER) // jump to "___SPLIT_ITER" if "_VAR1_" is not zero.
clear(_VAR2_),clear(_VAR1_)
{_SEP_}toksep
{_NEWARRAY_}
back

View file

@ -0,0 +1,20 @@
on run
intercalate(".", splitOn(",", "Hello,How,Are,You,Today"))
end run
-- splitOn :: String -> String -> [String]
on splitOn(strDelim, strMain)
set {dlm, my text item delimiters} to {my text item delimiters, strDelim}
set lstParts to text items of strMain
set my text item delimiters to dlm
return lstParts
end splitOn
-- intercalate :: String -> [String] -> String
on intercalate(strText, lstText)
set {dlm, my text item delimiters} to {my text item delimiters, strText}
set strJoined to lstText as text
set my text item delimiters to dlm
return strJoined
end intercalate

View file

@ -0,0 +1,5 @@
set my text item delimiters to ","
set tokens to the text items of "Hello,How,Are,You,Today"
set my text item delimiters to "."
log tokens as text

View file

@ -0,0 +1,20 @@
100 T$ = "HELLO,HOW,ARE,YOU,TODAY"
110 GOSUB 200"TOKENIZE
120 FOR I = 1 TO N
130 PRINT A$(I) "." ;
140 NEXT
150 PRINT
160 END
200 IF N = 0 THEN DIM A$(256)
210 N = 1
220 A$(N) = "
230 FOR TI = 1 TO LEN(T$)
240 C$ = MID$(T$, TI, 1)
250 T = C$ = ","
260 IF T THEN C$ = "
270 N = N + T
280 IF T THEN A$(N) = C$
290 A$(N) = A$(N) + C$
300 NEXT TI
310 RETURN

View file

@ -0,0 +1,3 @@
str: "Hello,How,Are,You,Today"
print join.with:"." split.by:"," str

View file

@ -0,0 +1,3 @@
let text = 'Hello,How,Are,You,Today'
let tokens = text.split(||,||)
print tokens.join(with: '.')

View file

@ -0,0 +1,6 @@
string := "Hello,How,Are,You,Today"
stringsplit, string, string, `,
loop, % string0
{
msgbox % string%A_Index%
}

View file

@ -0,0 +1,7 @@
instring$ = "Hello,How,Are,You,Today"
tokens$ = explode(instring$,",")
for i = 0 to tokens$[?]-1
print tokens$[i]; ".";
next i
end

View file

@ -0,0 +1,8 @@
INSTALL @lib$+"STRINGLIB"
text$ = "Hello,How,Are,You,Today"
n% = FN_split(text$, ",", array$())
FOR i% = 0 TO n%-1
PRINT array$(i%) "." ;
NEXT
PRINT

View file

@ -0,0 +1,4 @@
Split((-˜+`׬)=)
(-˜+`׬)=
'.'´','Split"Hello,How,Are,You,Today"
"Hello.How.Are.You.Today"

View file

@ -0,0 +1,12 @@
OPTION BASE 1
string$ = "Hello,How,Are,You,Today"
' Tokenize a string into an array
SPLIT string$ BY "," TO array$
' Print array elements with new delimiter
PRINT COIL$(i, UBOUND(array$), array$[i], ".")
' Or simply replace the delimiter
PRINT DELIM$(string$, ",", ".")

View file

@ -0,0 +1,12 @@
@echo off
setlocal enabledelayedexpansion
call :tokenize %1 res
echo %res%
goto :eof
:tokenize
set str=%~1
:loop
for %%i in (%str%) do set %2=!%2!.%%i
set %2=!%2:~1!
goto :eof

View file

@ -0,0 +1,13 @@
( "Hello,How,Are,You,Today":?String
& :?ReverseList
& whl
' ( @(!String:?element "," ?String)
& !element !ReverseList:?ReverseList
)
& !String:?List
& whl
' ( !ReverseList:%?element ?ReverseList
& (!element.!List):?List
)
& out$!List
)

View file

@ -0,0 +1,13 @@
( get$("Hello,How,Are,You,Today",MEM):?CommaseparatedList
& :?ReverseList
& whl
' ( !CommaseparatedList:(?element,?CommaseparatedList)
& !element !ReverseList:?ReverseList
)
& !CommaseparatedList:?List
& whl
' ( !ReverseList:%?element ?ReverseList
& (!element.!List):?List
)
& out$!List
)

View file

@ -0,0 +1,16 @@
#include <string>
#include <sstream>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
int main()
{
std::string s = "Hello,How,Are,You,Today";
std::vector<std::string> v;
std::istringstream buf(s);
for(std::string token; getline(buf, token, ','); )
v.push_back(token);
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."));
std::cout << '\n';
}

View file

@ -0,0 +1,25 @@
#include <string>
#include <locale>
#include <sstream>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
struct comma_ws : std::ctype<char> {
static const mask* make_table() {
static std::vector<mask> v(classic_table(), classic_table() + table_size);
v[','] |= space; // comma will be classified as whitespace
return &v[0];
}
comma_ws(std::size_t refs = 0) : ctype<char>(make_table(), false, refs) {}
};
int main()
{
std::string s = "Hello,How,Are,You,Today";
std::istringstream buf(s);
buf.imbue(std::locale(buf.getloc(), new comma_ws));
std::istream_iterator<std::string> beg(buf), end;
std::vector<std::string> v(beg, end);
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."));
std::cout << '\n';
}

View file

@ -0,0 +1,14 @@
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <iostream>
#include <boost/tokenizer.hpp>
int main()
{
std::string s = "Hello,How,Are,You,Today";
boost::tokenizer<> tok(s);
std::vector<std::string> v(tok.begin(), tok.end());
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."))
std::cout << '\n';
}

View file

@ -0,0 +1,11 @@
#include <string>
#include <ranges>
#include <iostream>
int main() {
std::string s = "Hello,How,Are,You,Today";
s = s // Assign the final string back to the string variable
| std::views::split(',') // Produce a range of the comma separated words
| std::views::join_with('.') // Concatenate the words into a single range of characters
| std::ranges::to<std::string>(); // Convert the range of characters into a regular string
std::cout << s;
}

View file

@ -0,0 +1,5 @@
string str = "Hello,How,Are,You,Today";
// or Regex.Split ( "Hello,How,Are,You,Today", "," );
// (Regex is in System.Text.RegularExpressions namespace)
string[] strings = str.Split(',');
Console.WriteLine(String.Join(".", strings));

View file

@ -0,0 +1,22 @@
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
char *a[5];
const char *s="Hello,How,Are,You,Today";
int n=0, nn;
char *ds=strdup(s);
a[n]=strtok(ds, ",");
while(a[n] && n<4) a[++n]=strtok(NULL, ",");
for(nn=0; nn<=n; ++nn) printf("%s.", a[nn]);
putchar('\n');
free(ds);
return 0;
}

View file

@ -0,0 +1,26 @@
#include<stdio.h>
typedef void (*callbackfunc)(const char *);
void doprint(const char *s) {
printf("%s.", s);
}
void tokenize(char *s, char delim, callbackfunc cb) {
char *olds = s;
char olddelim = delim;
while(olddelim && *s) {
while(*s && (delim != *s)) s++;
*s ^= olddelim = *s; // olddelim = *s; *s = 0;
cb(olds);
*s++ ^= olddelim; // *s = olddelim; s++;
olds = s;
}
}
int main(void)
{
char array[] = "Hello,How,Are,You,Today";
tokenize(array, ',', doprint);
return 0;
}

View file

@ -0,0 +1,5 @@
bundle agent main
{
reports:
"${with}" with => join(".", splitstring("Hello,How,Are,You,Today", ",", 99));
}

View file

@ -0,0 +1,23 @@
% This iterator splits the string on a given character,
% and returns each substring in order.
tokenize = iter (s: string, c: char) yields (string)
while ~string$empty(s) do
next: int := string$indexc(c, s)
if next = 0 then
yield(s)
break
else
yield(string$substr(s, 1, next-1))
s := string$rest(s, next+1)
end
end
end tokenize
start_up = proc ()
po: stream := stream$primary_output()
str: string := "Hello,How,Are,You,Today"
for part: string in tokenize(str, ',') do
stream$putl(po, part || ".")
end
end start_up

View file

@ -0,0 +1,30 @@
identification division.
program-id. tokenize.
environment division.
configuration section.
repository.
function all intrinsic.
data division.
working-storage section.
01 period constant as ".".
01 cmma constant as ",".
01 start-with.
05 value "Hello,How,Are,You,Today".
01 items.
05 item pic x(6) occurs 5 times.
procedure division.
tokenize-main.
unstring start-with delimited by cmma
into item(1) item(2) item(3) item(4) item(5)
display trim(item(1)) period trim(item(2)) period
trim(item(3)) period trim(item(4)) period
trim(item(5))
goback.
end program tokenize.

View file

@ -0,0 +1,5 @@
shared void tokenizeAString() {
value input = "Hello,How,Are,You,Today";
value tokens = input.split(','.equals);
print(".".join(tokens));
}

View file

@ -0,0 +1 @@
(apply str (interpose "." (.split #"," "Hello,How,Are,You,Today")))

View file

@ -0,0 +1 @@
(clojure.string/join "." (clojure.string/split "Hello,How,Are,You,Today" #","))

View file

@ -0,0 +1,2 @@
arr = "Hello,How,Are,You,Today".split ","
console.log arr.join "."

View file

@ -0,0 +1,4 @@
<cfoutput>
<cfset wordListTag = "Hello,How,Are,You,Today">
#Replace( wordListTag, ",", ".", "all" )#
</cfoutput>

View file

@ -0,0 +1,5 @@
<cfscript>
wordList = "Hello,How,Are,You,Today";
splitList = replace( wordList, ",", ".", "all" );
writeOutput( splitList );
</cfscript>

View file

@ -0,0 +1,17 @@
10 REM TOKENIZE A STRING ... ROSETTACODE.ORG
20 T$ = "HELLO,HOW,ARE,YOU,TODAY"
30 GOSUB 200, TOKENIZE
40 FOR I = 1 TO N
50 PRINT A$(I) "." ;
60 NEXT
70 PRINT
80 END
200 IF N = 0 THEN DIM A$(256)
210 N = 1
220 A$(N) = ""
230 FOR L = 1 TO LEN(T$)
240 C$ = MID$(T$, L, 1)
250 IF C$<>"," THEN A$(N) = A$(N) + C$: GOTO 270
260 N = N + 1
270 NEXT L
280 RETURN

View file

@ -0,0 +1,8 @@
(defun comma-split (string)
(loop for start = 0 then (1+ finish)
for finish = (position #\, string :start start)
collecting (subseq string start finish)
until (null finish)))
(defun write-with-periods (strings)
(format t "~{~A~^.~}" strings))

View file

@ -0,0 +1,40 @@
include "cowgol.coh";
include "strings.coh";
# Tokenize a string. Note: the string is modified in place.
sub tokenize(sep: uint8, str: [uint8], out: [[uint8]]): (length: intptr) is
length := 0;
loop
[out] := str;
out := @next out;
length := length + 1;
while [str] != 0 and [str] != sep loop
str := @next str;
end loop;
if [str] == sep then
[str] := 0;
str := @next str;
else
break;
end if;
end loop;
end sub;
# The string
var string: [uint8] := "Hello,How,Are,You,Today";
# Make a mutable copy
var buf: uint8[64];
CopyString(string, &buf[0]);
# Tokenize the copy
var parts: [uint8][64];
var length := tokenize(',', &buf[0], &parts[0]) as @indexof parts;
# Print each string
var i: @indexof parts := 0;
while i < length loop
print(parts[i]);
print(".\n");
i := i + 1;
end loop;

View file

@ -0,0 +1 @@
puts "Hello,How,Are,You,Today".split(',').join('.')

View file

@ -0,0 +1,5 @@
void main() {
import std.stdio, std.string;
"Hello,How,Are,You,Today".split(',').join('.').writeln;
}

View file

@ -0,0 +1,16 @@
program Tokenize_a_string;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
var
Words: TArray<string>;
begin
Words := 'Hello,How,Are,You,Today'.Split([',']);
Writeln(string.Join(#10, Words));
Readln;
end.

View file

@ -0,0 +1,32 @@
program TokenizeString;
{$APPTYPE CONSOLE}
uses
Classes;
var
tmp: TStringList;
i: Integer;
begin
// Instantiate TStringList class
tmp := TStringList.Create;
try
{ Use the TStringList's CommaText property to get/set
all the strings in a single comma-delimited string }
tmp.CommaText := 'Hello,How,Are,You,Today';
{ Now loop through the TStringList and display each
token on the console }
for i := 0 to Pred(tmp.Count) do
Writeln(tmp[i]);
finally
tmp.Free;
end;
Readln;
end.

View file

@ -0,0 +1,5 @@
Hello
How
Are
You
Today

View file

@ -0,0 +1,3 @@
var str = "Hello,How,Are,You,Today"
var strings = str.Split(',')
print(values: strings, separator: ".")

View file

@ -0,0 +1 @@
".".rjoin("Hello,How,Are,You,Today".split(","))

View file

@ -0,0 +1,5 @@
text value = "Hello,How,Are,You,Today"
List tokens = value.split(",")
writeLine(tokens.join("."))
# single line version
writeLine("Hello,How,Are,You,Today".split(",").join("."))

View file

@ -0,0 +1,12 @@
import system'routines;
import extensions;
public program()
{
var string := "Hello,How,Are,You,Today";
string.splitBy:",".forEach:(s)
{
console.print(s,".")
}
}

View file

@ -0,0 +1,2 @@
tokens = String.split("Hello,How,Are,You,Today", ",")
IO.puts Enum.join(tokens, ".")

View file

@ -0,0 +1,7 @@
-module(tok).
-export([start/0]).
start() ->
Lst = string:tokens("Hello,How,Are,You,Today",","),
io:fwrite("~s~n", [string:join(Lst,".")]),
ok.

View file

@ -0,0 +1,22 @@
function split(sequence s, integer c)
sequence out
integer first, delim
out = {}
first = 1
while first<=length(s) do
delim = find_from(c,s,first)
if delim = 0 then
delim = length(s)+1
end if
out = append(out,s[first..delim-1])
first = delim + 1
end while
return out
end function
sequence s
s = split("Hello,How,Are,You,Today", ',')
for i = 1 to length(s) do
puts(1, s[i] & ',')
end for

View file

@ -0,0 +1 @@
System.String.Join(".", "Hello,How,Are,You,Today".Split(','))

View file

@ -0,0 +1 @@
"Hello,How,Are,You,Today" "," split "." join print

View file

@ -0,0 +1,13 @@
/* created by Aykayayciti Earl Lamont Montgomery
April 9th, 2018 */
a = []
a = strSplit("Hello,How,Are,You,Today", ",")
index = 0
start = 0
b = ""
for index in [ start : len(a)-1 : 1 ]
b = b + a[index] + "."
end
> b

View file

@ -0,0 +1,12 @@
class Main
{
public static Void main ()
{
str := "Hello,How,Are,You,Today"
words := str.split(',')
words.each |Str word|
{
echo ("${word}. ")
}
}
}

View file

@ -0,0 +1,8 @@
(fn string.split [self sep]
(let [pattern (string.format "([^%s]+)" sep)
fields {}]
(self:gsub pattern (fn [c] (tset fields (+ 1 (length fields)) c)))
fields))
(let [str "Hello,How,Are,You,Today"]
(print (table.concat (str:split ",") ".")))

View file

@ -0,0 +1,18 @@
: split ( str len separator len -- tokens count )
here >r 2swap
begin
2dup 2, \ save this token ( addr len )
2over search \ find next separator
while
dup negate here 2 cells - +! \ adjust last token length
2over nip /string \ start next search past separator
repeat
2drop 2drop
r> here over - ( tokens length )
dup negate allot \ reclaim dictionary
2 cells / ; \ turn byte length into token count
: .tokens ( tokens count -- )
1 ?do dup 2@ type ." ." cell+ cell+ loop 2@ type ;
s" Hello,How,Are,You,Today" s" ," split .tokens \ Hello.How.Are.You.Today

View file

@ -0,0 +1,23 @@
PROGRAM Example
CHARACTER(23) :: str = "Hello,How,Are,You,Today"
CHARACTER(5) :: word(5)
INTEGER :: pos1 = 1, pos2, n = 0, i
DO
pos2 = INDEX(str(pos1:), ",")
IF (pos2 == 0) THEN
n = n + 1
word(n) = str(pos1:)
EXIT
END IF
n = n + 1
word(n) = str(pos1:pos1+pos2-2)
pos1 = pos2+pos1
END DO
DO i = 1, n
WRITE(*,"(2A)", ADVANCE="NO") TRIM(word(i)), "."
END DO
END PROGRAM Example

View file

@ -0,0 +1,22 @@
sub tokenize( instring as string, tokens() as string, sep as string )
redim tokens(0 to 0) as string
dim as string*1 ch
dim as uinteger t=0
for i as uinteger = 1 to len(instring)
ch = mid(instring,i,1)
if ch = sep then
t = t + 1
redim preserve tokens(0 to t)
else
tokens(t) = tokens(t) + ch
end if
next i
return
end sub
dim as string instring = "Hello,How,Are,You,Today"
redim as string tokens(-1)
tokenize( instring, tokens(), "," )
for i as uinteger = 0 to ubound(tokens)
print tokens(i);".";
next i

View file

@ -0,0 +1 @@
println[join[".", split[",", "Hello,How,Are,You,Today"]]]

View file

@ -0,0 +1,11 @@
window 1, @"Tokenize a string"
void local fn DoIt
CFStringRef string = @"Hello,How,Are,You,Today"
CFArrayRef tokens = fn StringComponentsSeparatedByString( string, @"," )
print fn ArrayComponentsJoinedByString( tokens, @"." )
end fn
fn DoIt
HandleEvents

View file

@ -0,0 +1,5 @@
SplitString("Hello,How,Are,You,Today", ",");
# [ "Hello", "How", "Are", "You", "Today" ]
JoinStringsWithSeparator(last, ".");
# "Hello.How.Are.You.Today"

View file

@ -0,0 +1,6 @@
Public Sub Main()
Dim sString As String[] = Split("Hello,How,Are,You,Today")
Print sString.Join(".")
End

View file

@ -0,0 +1,7 @@
[indent=4]
init
str:string = "Hello,How,Are,You,Today"
words:array of string[] = str.split(",")
joined:string = string.joinv(".", words)
print joined

View file

@ -0,0 +1,11 @@
package main
import (
"fmt"
"strings"
)
func main() {
s := "Hello,How,Are,You,Today"
fmt.Println(strings.Join(strings.Split(s, ","), "."))
}

View file

@ -0,0 +1 @@
println 'Hello,How,Are,You,Today'.split(',').join('.')

View file

@ -0,0 +1,5 @@
{-# OPTIONS_GHC -XOverloadedStrings #-}
import Data.Text (splitOn,intercalate)
import qualified Data.Text.IO as T (putStrLn)
main = T.putStrLn . intercalate "." $ splitOn "," "Hello,How,Are,You,Today"

View file

@ -0,0 +1,16 @@
splitBy :: (a -> Bool) -> [a] -> [[a]]
splitBy _ [] = []
splitBy f list = first : splitBy f (dropWhile f rest) where
(first, rest) = break f list
splitRegex :: Regex -> String -> [String]
joinWith :: [a] -> [[a]] -> [a]
joinWith d xs = concat $ List.intersperse d xs
-- "concat $ intersperse" can be replaced with "intercalate" from the Data.List in GHC 6.8 and later
putStrLn $ joinWith "." $ splitBy (== ',') $ "Hello,How,Are,You,Today"
-- using regular expression to split:
import Text.Regex
putStrLn $ joinWith "." $ splitRegex (mkRegex ",") $ "Hello,How,Are,You,Today"

View file

@ -0,0 +1,6 @@
*Main> mapM_ putStrLn $ takeWhile (not.null) $ unfoldr (Just . second(drop 1). break (==',')) "Hello,How,Are,You,Today"
Hello
How
Are
You
Today

View file

@ -0,0 +1,13 @@
CHARACTER string="Hello,How,Are,You,Today", list
nWords = INDEX(string, ',', 256) + 1
maxWordLength = LEN(string) - 2*nWords
ALLOCATE(list, nWords*maxWordLength)
DO i = 1, nWords
EDIT(Text=string, SePaRators=',', item=i, WordEnd, CoPyto=CHAR(i, maxWordLength, list))
ENDDO
DO i = 1, nWords
WRITE(APPend) TRIM(CHAR(i, maxWordLength, list)), '.'
ENDDO

View file

@ -0,0 +1,9 @@
procedure main()
A := []
"Hello,How,Are,You,Today" ? {
while put(A, 1(tab(upto(',')),=","))
put(A,tab(0))
}
every writes(!A,".")
write()
end

View file

@ -0,0 +1,7 @@
import util
procedure main()
A := stringToList("Hello,How,Are,You,Today", ',')
every writes(!A,".")
write()
end

View file

@ -0,0 +1 @@
"Hello,How,Are,You,Today" split(",") join(".") println

View file

@ -0,0 +1,10 @@
s=: 'Hello,How,Are,You,Today'
] t=: <;._1 ',',s
+-----+---+---+---+-----+
|Hello|How|Are|You|Today|
+-----+---+---+---+-----+
; t,&.>'.'
Hello.How.Are.You.Today.
'.' (I.','=s)}s NB. two steps combined
Hello.How.Are.You.Today

View file

@ -0,0 +1,8 @@
require 'strings'
',' splitstring s
+-----+---+---+---+-----+
|Hello|How|Are|You|Today|
+-----+---+---+---+-----+
'.' joinstring ',' splitstring s
Hello.How.Are.You.Today

View file

@ -0,0 +1,2 @@
'"'([ ,~ ,) '","' joinstring ',' splitstring s
"Hello","How","Are","You","Today"

View file

@ -0,0 +1,2 @@
rplc&',.' s
Hello.How.Are.You.Today

View file

@ -0,0 +1 @@
fn;._2 string,','

View file

@ -0,0 +1 @@
fn ((;._2)(@(,&','))) string

View file

@ -0,0 +1,2 @@
String toTokenize = "Hello,How,Are,You,Today";
System.out.println(String.join(".", toTokenize.split(",")));

View file

@ -0,0 +1,7 @@
String toTokenize = "Hello,How,Are,You,Today";
String words[] = toTokenize.split(",");//splits on one comma, multiple commas yield multiple splits
//toTokenize.split(",+") if you want to ignore empty fields
for(int i=0; i<words.length; i++) {
System.out.print(words[i] + ".");
}

View file

@ -0,0 +1,6 @@
String toTokenize = "Hello,How,Are,You,Today";
StringTokenizer tokenizer = new StringTokenizer(toTokenize, ",");
while(tokenizer.hasMoreTokens()) {
System.out.print(tokenizer.nextToken() + ".");
}

View file

@ -0,0 +1 @@
alert( "Hello,How,Are,You,Today".split(",").join(".") );

View file

@ -0,0 +1 @@
split(",") | join(".")

View file

@ -0,0 +1,3 @@
$ jq -r 'split(",") | join(".")'
"Hello,How,Are,You,Today"
Hello.How.Are.You.Today

View file

@ -0,0 +1 @@
puts('Hello,How,Are,You,Today'.split(',').join('.'))

View file

@ -0,0 +1,7 @@
s = "Hello,How,Are,You,Today"
a = split(s, ",")
t = join(a, ".")
println("The string \"", s, "\"")
println("Splits into ", a)
println("Reconstitutes to \"", t, "\"")

View file

@ -0,0 +1,2 @@
words: "," \: "Hello,How,Are,You,Today"
"." /: words

View file

@ -0,0 +1,6 @@
","\"Hello,How,Are,You,Today"
("Hello"
"How"
"Are"
"You"
"Today")

View file

@ -0,0 +1,3 @@
( "Hello,How,Are,You,Today" "," ) split len [ get print "." print ] for
nl "End " input

Some files were not shown because too many files have changed in this diff Show more