Tokenize a string: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎version 2: changed the first comment to relect the REXX program's description. -- ~~~~)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(260 intermediate revisions by more than 100 users not shown)
Line 1:
{{task|String manipulation}}
[[Category:Simple]]
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.
 
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>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">V text = ‘Hello,How,Are,You,Today’
V tokens = text.split(‘,’)
print(tokens.join(‘.’))</syntaxhighlight>
 
{{out}}
<pre>
Hello.How.Are.You.Today
</pre>
 
=={{header|360 Assembly}}==
<syntaxhighlight lang="360asm">* 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</syntaxhighlight>
{{out}}
<pre>
Hello.How.Are.You.Today
</pre>
 
=={{header|8080 Assembly}}==
<syntaxhighlight lang="8080asm">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 $</syntaxhighlight>
{{out}}
<pre>Hello. How. Are. You. Today.</pre>
=={{header|8086 Assembly}}==
<syntaxhighlight lang="asm"> 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</syntaxhighlight>
{{out}}
<pre>Hello. How. Are. You. Today. </pre>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* 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"
</syntaxhighlight>
{{Output}}
<pre>
Words are :
Hello
How
Are
You
Today
</pre>
 
=={{header|ACL2}}==
<langsyntaxhighlight lang="lisp">(defun split-at (xs delim)
(if (or (endp xs) (eql (first xs) delim))
(mv nil (rest xs))
Line 31 ⟶ 389:
(progn$ (cw (first strs))
(cw (coerce (list delim) 'string))
(print-with (rest strs) delim))))</langsyntaxhighlight>
 
{{out}}
Output:
<pre>&gt; (print-with (split-str "Hello,How,Are,You,Today" #\,) #\.)
Hello.How.Are.You.Today.</pre>
 
=={{header|Action!}}==
The user must type in the monitor the following command after compilation and before running the program!<pre>SET EndProg=*</pre>
{{libheader|Action! Tool Kit}}
<syntaxhighlight lang="action!">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</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Tokenize_a_string.png Screenshot from Atari 8-bit computer]
<pre>
Input:
"Hello,How,Are,You,Today"
 
Split:
"Hello", "How", "Are", "You", "Today"
 
Join:
"Hello.How.Are.You.Today"
</pre>
 
=={{header|ActionScript}}==
<langsyntaxhighlight lang="actionscript">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("."));</langsyntaxhighlight>
 
=={{header|Ada}}==
<langsyntaxhighlight lang="ada">with Ada.Text_IO, Ada.Containers.Indefinite_Vectors, Ada.Strings.Fixed; use, Ada.Strings.FixedMaps;
use Ada.Text_IO, Ada.Containers, Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps;
with Ada.Text_Io; use Ada.Text_Io;
 
procedure Parse_CommasTokenize is
package String_Vectors is new Indefinite_Vectors (Positive, String);
Source_String : String := "Hello,How,Are,You,Today";
use String_Vectors;
Index_List : array(Source_String'Range) of Natural;
Next_IndexInput : NaturalString := Index_List'First"Hello,How,Are,You,Today";
Start : Positive := Input'First;
Finish : Natural := 0;
Output : Vector := Empty_Vector;
begin
while Start <= Input'Last loop
Index_List(Next_Index) := Source_String'First;
Find_Token (Input, To_Set (','), Start, Outside, Start, Finish);
while Index_List(Next_Index) < Source_String'Last loop
Next_Indexexit :=when Next_IndexStart +> 1Finish;
Output.Append (Input (Start .. Finish));
Index_List(Next_Index) := 1 + Index(Source_String(Index_List(Next_Index - 1)..Source_String'Last), ",");
if Index_List(Next_Index)Start := 1Finish then+ 1;
Index_List(Next_Index) := Source_String'Last + 2;
end if;
Put(Source_String(Index_List(Next_Index - 1)..Index_List(Next_Index)-2) & ".");
end loop;
for S of Output loop
end Parse_Commas;</lang>
Put (S & ".");
end loop;
end Tokenize;</syntaxhighlight>
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">main:(
 
OP +:= = (REF FLEX[]STRING in out, STRING item)VOID:(
Line 114 ⟶ 585:
printf(($g"."$, string split(beetles, ", "),$l$));
printf(($g"."$, char split(beetles, ", "),$l$))
)</langsyntaxhighlight>
{{out}}
Output:
<pre>
John Lennon.Paul McCartney.George Harrison.Ringo Starr.
John.Lennon..Paul.McCartney..George.Harrison..Ringo.Starr.
</pre>
 
=={{header|Amazing Hopper}}==
 
Hopper provides instructions for separating and modifying tokens from a string.
Let "s" be a string; "n" token number:
 
1) {n}, $(s) ==> gets token "n" from string "s".
 
2) {"word", n} $$(s) ==> replace token "n" of "s", with "word".
 
Note: the "splitnumber" macro cannot separate a number converted to a string by the "XTOSTR" function, because this function "rounds" the number to the decimal position by default.
 
<syntaxhighlight lang="hopper">
#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
 
</syntaxhighlight>
{{Out}}
<pre>Output:
 
String: this string will be separated into parts with space token separator
Array:
this,string,will,be,separated,into,parts,with,space,token,separator
Size=1,11
 
Original number: -125.49
Integer part: -125
Decimal part: 489922
 
Date by DATENOW(TODAY) macro: 22/11/2021,18:41:20:13
Date: 22/11/2021
Time: 18:41:20:13
 
</pre>
 
=={{header|APL}}==
<syntaxhighlight lang="apl"> '.',⍨¨ ','(≠⊆⊢)'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.
</syntaxhighlight>
 
=={{header|AppleScript}}==
 
<syntaxhighlight lang="applescript">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</syntaxhighlight>
{{Out}}
<pre>Hello.How.Are.You.Today</pre>
 
Or,
 
<syntaxhighlight lang="applescript">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</syntaxhighlight>
 
{{Out}}
 
<pre>Hello.How.Are.You.Today</pre>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
 
/* 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
</syntaxhighlight>
 
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">str: "Hello,How,Are,You,Today"
 
print join.with:"." split.by:"," str</syntaxhighlight>
 
{{out}}
 
<pre>Hello.How.Are.You.Today</pre>
 
=={{header|Astro}}==
<syntaxhighlight lang="python">let text = 'Hello,How,Are,You,Today'
let tokens = text.split(||,||)
print tokens.join(with: '.')</syntaxhighlight>
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">string := "Hello,How,Are,You,Today"
stringsplit, string, string, `,
loop, % string0
{
msgbox % string%A_Index%
}</langsyntaxhighlight>
 
=={{header|AWK}}==
 
<langsyntaxhighlight lang="awk">BEGIN {
s = "Hello,How,Are,You,Today"
split(s, arr, ",")
Line 136 ⟶ 928:
}
print
}</langsyntaxhighlight>
 
A more ''idiomatic'' way for AWK is
 
<langsyntaxhighlight lang="awk">BEGIN { FS = "," }
{
for(i=1; i <= NF; i++) printf $i ".";
print ""
}</langsyntaxhighlight>
 
which "tokenize" each line of input and this is achieved by using "," as field separator
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
{{works with|QBasic}}
<syntaxhighlight lang="applesoftbasic">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)
<lang qbasic>DIM parseMe AS STRING
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</syntaxhighlight>
 
==={{header|BaCon}}===
BaCon includes extensive support for ''delimited strings''.
<syntaxhighlight lang="bacon">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$, ",", ".")</syntaxhighlight>
 
{{out}}
<pre>prompt$ ./tokenize
Hello.How.Are.You.Today
Hello.How.Are.You.Today</pre>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">instring$ = "Hello,How,Are,You,Today"
 
tokens$ = explode(instring$,",")
for i = 0 to tokens$[?]-1
print tokens$[i]; ".";
next i
end</syntaxhighlight>
 
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> 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</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
Solutions [[#Applesoft BASIC|Applesoft BASIC]] and [[#Commodore BASIC|Commodore BASIC]] work without changes.
 
==={{header|Commodore BASIC}}===
Based on the AppleSoft BASIC version.
<syntaxhighlight lang="commodorebasic">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</syntaxhighlight>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">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</syntaxhighlight>
 
==={{header|Liberty BASIC}}===
<syntaxhighlight lang="lb">'Note that Liberty Basic's array usage can reach element #10 before having to DIM the array
For i = 0 To 4
array$(i) = Word$("Hello,How,Are,You,Today", (i + 1), ",")
array$ = array$ + array$(i) + "."
Next i
 
Print Left$(array$, (Len(array$) - 1))</syntaxhighlight>
 
==={{header|MSX Basic}}===
The [[#Commodore BASIC|Commodore BASIC]] solution works without any changes.
 
==={{header|PowerBASIC}}===
PowerBASIC has a few keywords that make parsing strings trivial: <code>PARSE</code>, <code>PARSE$</code>, and <code>PARSECOUNT</code>. (<code>PARSE$</code>, not shown here, is for extracting tokens one at a time, while <code>PARSE</code> extracts all tokens at once into an array. <code>PARSECOUNT</code> returns the number of tokens found.)
 
<syntaxhighlight lang="powerbasic">FUNCTION PBMAIN () AS LONG
DIM parseMe AS STRING
parseMe = "Hello,How,Are,You,Today"
 
REDIM parsed(PARSECOUNT(parseMe) - 1) AS STRING
PARSE parseMe, parsed() 'comma is default delimiter
 
DIM L0 AS LONG, outP AS STRING
outP = parsed(0)
FOR L0 = 1 TO UBOUND(parsed) 'could reuse parsecount instead of ubound
outP = outP & "." & parsed(L0)
NEXT
 
MSGBOX outP
END FUNCTION</syntaxhighlight>
 
==={{header|PureBasic}}===
 
'''As described
<syntaxhighlight lang="purebasic">NewList MyStrings.s()
 
For i=1 To 5
AddElement(MyStrings())
MyStrings()=StringField("Hello,How,Are,You,Today",i,",")
Next i
 
ForEach MyStrings()
Print(MyStrings()+".")
Next</syntaxhighlight>
 
'''Still, easier would be
<syntaxhighlight lang="purebasic">Print(ReplaceString("Hello,How,Are,You,Today",",","."))</syntaxhighlight>
 
==={{header|QBasic}}===
<syntaxhighlight lang="qbasic">DIM parseMe AS STRING
parseMe = "Hello,How,Are,You,Today"
 
Line 195 ⟶ 1,144:
PRINT "."; parsed(L0);
NEXT
END IF</langsyntaxhighlight>
 
==={{header|Run BASIC}}===
<syntaxhighlight lang="runbasic">text$ = "Hello,How,Are,You,Today"
FOR i = 1 to 5
textArray$(i) = word$(text$,i,",")
print textArray$(i);" ";
NEXT</syntaxhighlight>
 
==={{header|VBScript}}===
====One liner====
<syntaxhighlight lang="vb">WScript.Echo Join(Split("Hello,How,Are,You,Today", ","), ".")</syntaxhighlight>
 
In fact, the Visual Basic solution (below) could have done the same, as Join() is available.
 
==={{header|Visual Basic}}===
{{trans|PowerBASIC}}
 
Unlike PowerBASIC, there is no need to know beforehand how many tokens are in the string -- <code>Split</code> automagically builds the array for you.
 
<syntaxhighlight lang="vb">Sub Main()
Dim parseMe As String, parsed As Variant
parseMe = "Hello,How,Are,You,Today"
 
parsed = Split(parseMe, ",")
 
Dim L0 As Long, outP As String
outP = parsed(0)
For L0 = 1 To UBound(parsed)
outP = outP & "." & parsed(L0)
Next
 
MsgBox outP
End Sub</syntaxhighlight>
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">@echo off
setlocal enabledelayedexpansion
call :tokenize %1 res
Line 209 ⟶ 1,191:
for %%i in (%str%) do set %2=!%2!.%%i
set %2=!%2:~1!
goto :eof</langsyntaxhighlight>
 
''Demo''
Line 215 ⟶ 1,197:
Hello.How.Are.You.Today
 
=={{header|BBC BASICBQN}}==
Uses a splitting idiom from bqncrate.
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bqn">Split ← (+`׬)⊸-∘= ⊔ ⊢
<lang bbcbasic> INSTALL @lib$+"STRINGLIB"
 
∾⟜'.'⊸∾´ ',' text$ =Split "Hello,How,Are,You,Today"</syntaxhighlight>
{{out}}
n% = FN_split(text$, ",", array$())
<pre>"Hello.How.Are.You.Today"</pre>
FOR i% = 0 TO n%-1
PRINT array$(i%) "." ;
NEXT
PRINT</lang>
 
=={{header|Bracmat}}==
Solution that employs string pattern matching to spot the commas
<langsyntaxhighlight lang="bracmat">( "Hello,How,Are,You,Today":?String
& :?ReverseList
& whl
Line 240 ⟶ 1,219:
)
& out$!List
)</langsyntaxhighlight>
Solution that starts by evaluating the input and employs the circumstance that the comma is a list constructing binary operator and that the string does not contain any other characters that are interpreted as operators on evaluation.
<langsyntaxhighlight lang="bracmat">( get$("Hello,How,Are,You,Today",MEM):?CommaseparatedList
& :?ReverseList
& whl
Line 254 ⟶ 1,233:
)
& out$!List
)</langsyntaxhighlight>
 
=={{header|C}}==
Line 263 ⟶ 1,242:
This example uses the ''strtok()'' function to separate the tokens. This function is destructive (replacing token separators with '\0'), so we have to make a copy of the string (using ''strdup()'') before tokenizing. ''strdup()'' is not part of [[ANSI C]], but is available on most platforms. It can easily be implemented with a combination of ''strlen()'', ''malloc()'', and ''strcpy()''.
 
<langsyntaxhighlight lang="c">#include<string.h>
#include<stdio.h>
#include<stdlib.h>
Line 284 ⟶ 1,263:
 
return 0;
}</langsyntaxhighlight>
 
Another way to accomplish the task without the built-in string functions is to temporarily modify the separator character. This method does not need any additional memory, but requires the input string to be writeable.
<langsyntaxhighlight lang="c">#include<stdio.h>
 
typedef (void (*callbackfunc)(const char *);
 
void doprint(const char *s) {
Line 295 ⟶ 1,274:
}
 
void tokenize(char *s, char delim, callbackfunc *cb) {
char *olds = s;
char olddelim = delim;
Line 312 ⟶ 1,291:
tokenize(array, ',', doprint);
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">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(',');
foreach Console.WriteLine(string s inString.Join(".", strings));
</syntaxhighlight>
{
Console.WriteLine (s + ".");
}</lang>
 
=={{header|C++}}==
Line 329 ⟶ 1,306:
std::getline() is typically used to tokenize strings on a single-character delimiter
 
<langsyntaxhighlight lang="cpp">#include <string>
#include <sstream>
#include <vector>
Line 344 ⟶ 1,321:
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."));
std::cout << '\n';
}</langsyntaxhighlight>
 
{{works with|C++98}}
C++ allows the user to redefine what is considered whitespace. If the delimiter is whitespace, tokenization becomes effortless.
 
<langsyntaxhighlight lang="cpp">#include <string>
#include <locale>
#include <sstream>
Line 373 ⟶ 1,350:
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."));
std::cout << '\n';
}</langsyntaxhighlight>
 
{{works with|C++98}}
Line 379 ⟶ 1,356:
The boost library has multiple options for easy tokenization.
 
<langsyntaxhighlight lang="cpp">#include <string>
#include <vector>
#include <iterator>
Line 392 ⟶ 1,369:
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."))
std::cout << '\n';
}</langsyntaxhighlight>
 
{{works with|C++23}}
C++20 and C++23 drastically improve the ergonomics of simple manipulation of ranges.
 
<syntaxhighlight lang="cpp">#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;
}</syntaxhighlight>
 
=={{header|Ceylon}}==
{{works with|Ceylon 1.2}}
<syntaxhighlight lang="ceylon">shared void tokenizeAString() {
value input = "Hello,How,Are,You,Today";
value tokens = input.split(','.equals);
print(".".join(tokens));
}</syntaxhighlight>
 
=={{header|CFEngine}}==
<syntaxhighlight lang="cfengine">bundle agent main
{
reports:
"${with}" with => join(".", splitstring("Hello,How,Are,You,Today", ",", 99));
}
</syntaxhighlight>
{{out}}
<pre>cf-agent -KIf ./tokenize-a-string.cf
R: Hello.How.Are.You.Today</pre>
 
See https://docs.cfengine.com/docs/master/reference-functions.html for a complete list of available functions.
 
=={{header|Clojure}}==
Using native Clojure functions and Java Interop:
<syntaxhighlight lang="clojure">(apply str (interpose "." (.split #"," "Hello,How,Are,You,Today")))</syntaxhighlight>
 
Using the clojure.string library:
<syntaxhighlight lang="clojure">(clojure.string/join "." (clojure.string/split "Hello,How,Are,You,Today" #","))</syntaxhighlight>
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">% 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</syntaxhighlight>
{{out}}
<pre>Hello.
How.
Are.
You.
Today.</pre>
 
=={{header|COBOL}}==
This can be made to handle more complex cases; UNSTRING allows multiple delimiters, capture of which delimiter was used for each field, a POINTER for starting position (set on ending), along with match TALLYING.
 
<syntaxhighlight lang="cobol">
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.
</syntaxhighlight>
 
{{out}}
<pre>
prompt$ cobc -xj tokenize.cob
Hello.How.Are.You.Today
</pre>
 
=={{header|CoffeeScript}}==
 
<langsyntaxhighlight lang="coffeescript">
arr = "Hello,How,Are,You,Today".split ","
console.log arr.join "."
</syntaxhighlight>
</lang>
 
=={{header|ColdFusion}}==
=== Classic tag based CFML ===
<syntaxhighlight lang="cfm">
<cfoutput>
<cfset wordListTag = "Hello,How,Are,You,Today">
#Replace( wordListTag, ",", ".", "all" )#
</cfoutput>
</syntaxhighlight>
{{Output}}
<pre>
"Hello.How.Are.You.Today"
</pre>
 
=== Script Based CFML ===
<syntaxhighlight lang="cfm"><cfscript>
wordList = "Hello,How,Are,You,Today";
splitList = replace( wordList, ",", ".", "all" );
writeOutput( splitList );
</cfscript></syntaxhighlight>
{{Output}}
<pre>
"Hello.How.Are.You.Today"
</pre>
 
=={{header|Common Lisp}}==
Line 405 ⟶ 1,522:
There are libraries out there that handle splitting (e.g., [http://www.cliki.net/SPLIT-SEQUENCE SPLIT-SEQUENCE], and the more-general [http://weitz.de/cl-ppcre/ CL-PPCRE]), but this is a simple one-off, too. When the words are written with write-with-periods, there is no final period after the last word.
 
<langsyntaxhighlight lang="lisp">(defun comma-split (string)
(loop for start = 0 then (1+ finish)
for finish = (position #\, string :start start)
Line 412 ⟶ 1,529:
 
(defun write-with-periods (strings)
(format t "~{~A~^.~}" strings))</langsyntaxhighlight>
 
=={{header|ClojureCowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
<lang lisp>(apply str (interpose "." (seq (.split #"," "Hello,How,Are,You,Today"))))</lang>
include "strings.coh";
 
# Tokenize a string. Note: the string is modified in place.
=={{header|D}}==
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;
 
<lang# d>importThe std.stdio, std.string;
var string: [uint8] := "Hello,How,Are,You,Today";
 
# Make a mutable copy
void main() {
var buf: uint8[64];
"Hello,How,Are,You,Today".split(",").join(".").writeln();
CopyString(string, &buf[0]);
}</lang>
 
# 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;</syntaxhighlight>
{{out}}
<pre>Hello.
How.
Are.
You.
Today.</pre>
 
=={{header|Crystal}}==
<syntaxhighlight lang="crystal">puts "Hello,How,Are,You,Today".split(',').join('.')</syntaxhighlight>
{{out}}
<pre>Hello.How.Are.You.Today</pre>
 
=={{header|D}}==
<syntaxhighlight lang="d">void main() {
import std.stdio, std.string;
 
"Hello,How,Are,You,Today".split(',').join('.').writeln;
}</syntaxhighlight>
{{out}}
<pre>Hello.How.Are.You.Today</pre>
 
=={{header|Delphi}}==
=== Using String.split ===
{{libheader| System.SysUtils}}
<syntaxhighlight lang="delphi">
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.
 
</syntaxhighlight>
 
=== Using TStringList ===
<lang Delphi>
<syntaxhighlight lang="delphi">
program TokenizeString;
 
Line 462 ⟶ 1,650:
 
end.
</syntaxhighlight>
</lang>
 
The result is:
 
<syntaxhighlight lang="delphi">
<lang Delphi>
Hello
How
Line 472 ⟶ 1,660:
You
Today
</syntaxhighlight>
</lang>
 
=={{header|dt}}==
<syntaxhighlight lang="dt">"Hello,How,Are,You,Today" "," split "." join pl</syntaxhighlight>
 
=={{header|Dyalect}}==
<syntaxhighlight lang="dyalect">var str = "Hello,How,Are,You,Today"
var strings = str.Split(',')
print(values: strings, separator: ".")</syntaxhighlight>
{{out}}
<pre>Hello.How.Are.You.Today</pre>
 
=={{header|Déjà Vu}}==
<syntaxhighlight lang="dejavu">!print join "." split "Hello,How,Are,You,Today" ","</syntaxhighlight>
{{out}}
<pre>Hello.How.Are.You.Today</pre>
 
=={{header|E}}==
<langsyntaxhighlight lang="e">".".rjoin("Hello,How,Are,You,Today".split(","))</langsyntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
s$ = "Hello,How,Are,You,Today"
a$[] = strsplit s$ ","
for s$ in a$[]
write s$ & "."
.
</syntaxhighlight>
 
=={{header|Elena}}==
ELENA 6.x:
<syntaxhighlight lang="elena">import system'routines;
import extensions;
public program()
{
auto string := "Hello,How,Are,You,Today";
string.splitBy(",").forEach::(s)
{
console.print(s,".")
}
}</syntaxhighlight>
 
=={{header|Elixir}}==
<syntaxhighlight lang="elixir">
tokens = String.split("Hello,How,Are,You,Today", ",")
IO.puts Enum.join(tokens, ".")
</syntaxhighlight>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
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("."))
</syntaxhighlight>
{{out}}
<pre>
Hello.How.Are.You.Today
Hello.How.Are.You.Today
</pre>
 
=={{header|Erlang}}==
<langsyntaxhighlight lang="erlang">-module(tok).
-export([start/0]).
 
Line 484 ⟶ 1,731:
Lst = string:tokens("Hello,How,Are,You,Today",","),
io:fwrite("~s~n", [string:join(Lst,".")]),
ok.</langsyntaxhighlight>
 
=={{header|Euphoria}}==
<langsyntaxhighlight lang="euphoria">function split(sequence s, integer c)
sequence out
integer first, delim
Line 508 ⟶ 1,755:
for i = 1 to length(s) do
puts(1, s[i] & ',')
end for</langsyntaxhighlight>
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">System.String.Join(".", "Hello,How,Are,You,Today".Split(','))</syntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">"Hello,How,Are,You,Today" "," split "." join print</langsyntaxhighlight>
 
=={{header|Falcon}}==
'''VBA/Python programmer's approach to this solution, not sure if it's the most falconic way'''
<syntaxhighlight lang="falcon">
/* 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
</syntaxhighlight>
{{out}}
<pre>
Hello.How.Are.You.
[Finished in 0.2s]
</pre>
 
=={{header|Fantom}}==
Line 517 ⟶ 1,790:
A string can be split on a given character, returning a list of the intervening strings.
 
<langsyntaxhighlight lang="fantom">
class Main
{
Line 530 ⟶ 1,803:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Fennel}}==
{{trans|Lua}}
<syntaxhighlight lang="fennel">(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 ",") ".")))</syntaxhighlight>
 
=={{header|Forth}}==
There is no standard string split routine, but it is easily written. The results are saved temporarily to the dictionary.
 
<langsyntaxhighlight lang="forth">: split ( str len separator len -- tokens count )
here >r 2swap
begin
Line 552 ⟶ 1,836:
1 ?do dup 2@ type ." ." cell+ cell+ loop 2@ type ;
 
s" Hello,How,Are,You,Today" s" ," split .tokens \ Hello.How.Are.You.Today</langsyntaxhighlight>
 
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<langsyntaxhighlight lang="fortran">PROGRAM Example
 
CHARACTER(23) :: str = "Hello,How,Are,You,Today"
Line 578 ⟶ 1,862:
END DO
END PROGRAM Example</langsyntaxhighlight>
 
=={{header|Frink}}==
<syntaxhighlight lang="frink">
println[join[".", split[",", "Hello,How,Are,You,Today"]]]
</syntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
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
</syntaxhighlight>
{{out}}
<pre>
Hello.How.Are.You.Today
</pre>
 
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=218e240236cdf1419a405abfed906ed3 Click this link to run this code]'''
<syntaxhighlight lang="gambas">Public Sub Main()
Dim sString As String[] = Split("Hello,How,Are,You,Today")
 
Print sString.Join(".")
 
End</syntaxhighlight>
Output:
<pre>
Hello.How.Are.You.Today
</pre>
 
=={{header|GAP}}==
<langsyntaxhighlight lang="gap">SplitString("Hello,How,Are,You,Today", ",");
# [ "Hello", "How", "Are", "You", "Today" ]
 
JoinStringsWithSeparator(last, ".");
# "Hello.How.Are.You.Today"</langsyntaxhighlight>
 
=={{header|Genie}}==
<syntaxhighlight lang="genie">[indent=4]
 
init
str:string = "Hello,How,Are,You,Today"
words:array of string[] = str.split(",")
joined:string = string.joinv(".", words)
print joined</syntaxhighlight>
 
{{out}}
<pre>prompt$ valac tokenize.gs
prompt$ ./tokenize
Hello.How.Are.You.Today</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 598 ⟶ 1,933:
s := "Hello,How,Are,You,Today"
fmt.Println(strings.Join(strings.Split(s, ","), "."))
}</langsyntaxhighlight>
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">println 'Hello,How,Are,You,Today'.split(',').join('.')</langsyntaxhighlight>
 
=={{header|Haskell}}==
'''Using Data.Text'''
 
<syntaxhighlight lang="haskell">{-# 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"</syntaxhighlight>
 
Output: Hello.How.Are.You.Today
 
'''Alternate Solution'''
 
The necessary operations are unfortunately not in the standard library (yet), but simple to write:
 
<langsyntaxhighlight lang="haskell">splitBy :: (a -> Bool) -> [a] -> [[a]]
splitBy _ [] = []
splitBy f list = first : splitBy f (dropWhile f rest) where
Line 622 ⟶ 1,968:
-- using regular expression to split:
import Text.Regex
putStrLn $ joinWith "." $ splitRegex (mkRegex ",") $ "Hello,How,Are,You,Today"</langsyntaxhighlight>
 
Tokenizing can also be realized by using unfoldr and break:
<langsyntaxhighlight Haskelllang="haskell">*Main> mapM_ putStrLn $ takeWhile (not.null) $ unfoldr (Just . second(drop 1). break (==',')) "Hello,How,Are,You,Today"
Hello
How
Are
You
Today</langsyntaxhighlight>
* You need to import the modules Data.List and Control.Arrow
 
Line 636 ⟶ 1,982:
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">CHARACTER string="Hello,How,Are,You,Today", list
 
nWords = INDEX(string, ',', 256) + 1
Line 648 ⟶ 1,994:
DO i = 1, nWords
WRITE(APPend) TRIM(CHAR(i, maxWordLength, list)), '.'
ENDDO</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight lang="icon">procedure main()
A := []
"Hello,How,Are,You,Today" ? while put(A, 1(tab(upto(',')|0),=",")){
while put(A, 1(tab(upto(',')),=","))
put(A,tab(0))
}
every writes(!A,".")
write()
end</langsyntaxhighlight>
 
{{out}}
Output:
<pre>
->ss
Hello.How.Are.You.Today.
->
</pre>
 
A Unicon-specific solution is:
<syntaxhighlight lang="unicon">import util
 
procedure main()
A := stringToList("Hello,How,Are,You,Today", ',')
every writes(!A,".")
write()
end</syntaxhighlight>
 
One wonders what the expected output should be with the input string ",,,,".
 
=={{header|Io}}==
<langsyntaxhighlight lang="io">"Hello,How,Are,You,Today" split(",") join(".") println</langsyntaxhighlight>
 
=={{header|J}}==
<langsyntaxhighlight lang="j"> s=: 'Hello,How,Are,You,Today'
] t=: <;._1 ',',s
+-----+---+---+---+-----+
Line 676 ⟶ 2,038:
 
'.' (I.','=s)}s NB. two steps combined
Hello.How.Are.You.Today</langsyntaxhighlight>
 
Alternatively using the system library/script <tt>strings</tt>
<langsyntaxhighlight lang="j"> require 'strings'
',' splitstring s
+-----+---+---+---+-----+
Line 686 ⟶ 2,048:
 
'.' joinstring ',' splitstring s
Hello.How.Are.You.Today</langsyntaxhighlight>
 
<tt>splitstring</tt> and <tt>joinstring</tt> also work with longer "delimiters":
<langsyntaxhighlight lang="j"> '"'([ ,~ ,) '","' joinstring ',' splitstring s
"Hello","How","Are","You","Today"</langsyntaxhighlight>
 
But, of course, this could be solved with simple string replacement:
 
<langsyntaxhighlight Jlang="j"> rplc&',.' s
Hello.How.Are.You.Today</langsyntaxhighlight>
 
The task asks us to ''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.'' but for many purposes the original string is an adequate data structure. Note also that given a string, a list of "word start" indices and "word length" integers can be logically equivalent to having an "array of words" -- and, depending on implementation details may be a superior or inferior choice to some other representation. But, in current definition of this task, the concept of "word length" plays no useful role.
Line 701 ⟶ 2,063:
Note also that J provides several built-in concepts of parsing: split on leading delimiter, split on trailing delimiter, split J language words. Also, it's sometimes more efficient to append to a string than to prepend to it. So a common practice for parsing on an embedded delimiter is to append a copy of the delimiter to the string and then use the appended result:
 
<langsyntaxhighlight Jlang="j"> fn;._2 string,','</langsyntaxhighlight>
 
Here '''fn''' is applied to each ',' delimited substring and the results are assembled into an array.
 
Or, factoring out the names:
<langsyntaxhighlight Jlang="j"> fn ((;._2)(@(,&','))) string</langsyntaxhighlight>
 
=={{header|Java}}==
Line 714 ⟶ 2,076:
 
The first is by splitting the String into an array of Strings. The separator is actually a regular expression so you could do very powerful things with this, but make sure to escape any characters with special meaning in regex.
 
{{works with|Java|1.8+}}
 
<syntaxhighlight lang="java5">String toTokenize = "Hello,How,Are,You,Today";
System.out.println(String.join(".", toTokenize.split(",")));</syntaxhighlight>
 
{{works with|Java|1.4+}}
<langsyntaxhighlight lang="java5">String toTokenize = "Hello,How,Are,You,Today";
 
String words[] = toTokenize.split(",");//splits on one comma, multiple commas yield multiple splits
Line 722 ⟶ 2,089:
for(int i=0; i<words.length; i++) {
System.out.print(words[i] + ".");
}</langsyntaxhighlight>
 
The other way is to use StringTokenizer. It will skip any empty tokens. So if two commas are given in line, there will be an empty string in the array given by the split function, but no empty string with the StringTokenizer object. This method takes more code to use, but allows you to get tokens incrementally instead of all at once.
 
{{works with|Java|1.0+}}
<langsyntaxhighlight lang="java5">String toTokenize = "Hello,How,Are,You,Today";
 
StringTokenizer tokenizer = new StringTokenizer(toTokenize, ",");
while(tokenizer.hasMoreTokens()) {
System.out.print(tokenizer.nextToken() + ".");
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
<syntaxhighlight lang="javascript">console.log(
{{works with|Firefox|2.0}}
"Hello,How,Are,You,Today"
.split(",")
.join(".")
);</syntaxhighlight>A more advanced program to tokenise strings:<syntaxhighlight lang="javascript" line="1">
const Tokeniser = (function () {
const numberRegex = /-?(\d+\.d+|\d+\.|\.\d+|\d+)((e|E)(\+|-)?\d+)?/g;
return {
settings: {
operators: ["<", ">", "=", "+", "-", "*", "/", "?", "!"],
separators: [",", ".", ";", ":", " ", "\t", "\n"],
groupers: ["(", ")", "[", "]", "{", "}", '"', '"', "'", "'"],
keepWhiteSpacesAsTokens: false,
trimTokens: true
},
isNumber: function (value) {
if (typeof value === "number") {
return true;
} else if (typeof value === "string") {
return numberRegex.test(value);
}
return false;
},
closeGrouper: function (grouper) {
if (this.settings.groupers.includes(grouper)) {
return this.settings.groupers[this.settings.groupers.indexOf(grouper) + 1];
}
return null;
},
tokenType: function (char) {
if (this.settings.operators.includes(char)) {
return "operator";
} else if (this.settings.separators.includes(char)) {
return "separator";
} else if (this.settings.groupers.includes(char)) {
return "grouper";
}
return "other";
},
parseString: function (str) {
if (typeof str !== "string") {
if (str === null) {
return "null";
} if (typeof str === "object") {
str = JSON.stringify(str);
} else {
str = str.toString();
}
}
let tokens = [], _tempToken = "";
for (let i = 0; i < str.length; i++) {
if (this.tokenType(_tempToken) !== this.tokenType(str[i]) || this.tokenType(str[i]) === "separator") {
if (_tempToken.trim() !== "") {
tokens.push(this.settings.trimTokens ? _tempToken.trim() : _tempToken);
} else if (this.settings.keepWhiteSpacesAsTokens) {
tokens.push(_tempToken);
}
_tempToken = str[i];
if (this.tokenType(_tempToken) === "separator") {
if (_tempToken.trim() !== "") {
tokens.push(this.settings.trimTokens ? _tempToken.trim() : _tempToken);
} else if (this.settings.keepWhiteSpacesAsTokens) {
tokens.push(_tempToken);
}
_tempToken = "";
}
} else {
_tempToken += str[i];
}
}
if (_tempToken.trim() !== "") {
tokens.push(this.settings.trimTokens ? _tempToken.trim() : _tempToken);
} else if (this.settings.keepWhiteSpacesAsTokens) {
tokens.push(_tempToken);
}
return tokens.filter((token) => token !== "");
}
};
})();
</syntaxhighlight>Output:<syntaxhighlight lang="javascript">
Tokeniser.parseString("Hello,How,Are,You,Today");
 
<lang// javascript->alert( "['Hello', ',', 'How', ',', 'Are', ',', 'You',Today".split(" ',',").join(".") );</lang>'Today']
</syntaxhighlight>
 
=={{header|jq}}==
<syntaxhighlight lang="jq">split(",") | join(".")</syntaxhighlight>Example:<syntaxhighlight lang="sh">$ jq -r 'split(",") | join(".")'
"Hello,How,Are,You,Today"
Hello.How.Are.You.Today</syntaxhighlight>
 
=={{header|Jsish}}==
Being in the ECMAScript family, Jsi is blessed with many easy to use character, string and array manipulation routines.
 
<syntaxhighlight lang="javascript">puts('Hello,How,Are,You,Today'.split(',').join('.'))</syntaxhighlight>
{{out}}
<pre>Hello.How.Are.You.Today</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">
s = "Hello,How,Are,You,Today"
a = split(s, ",")
t = join(a, ".")
 
println("The string \"", s, "\"")
println("Splits into ", a)
println("Reconstitutes to \"", t, "\"")
</syntaxhighlight>
 
{{out}}
<pre>
The string "Hello,How,Are,You,Today"
Splits into SubString{ASCIIString}["Hello","How","Are","You","Today"]
Reconstitutes to "Hello.How.Are.You.Today"
</pre>
 
=={{header|K}}==
<syntaxhighlight lang="k">words: "," \: "Hello,How,Are,You,Today"
"." /: words</syntaxhighlight>
 
{{out}}
<pre>
"Hello.How.Are.You.Today"
</pre>
 
{{works with|ngn/k}}<syntaxhighlight lang=K>","\"Hello,How,Are,You,Today"
("Hello"
"How"
"Are"
"You"
"Today")</syntaxhighlight>
 
=={{header|Klingphix}}==
<syntaxhighlight lang="klingphix">( "Hello,How,Are,You,Today" "," ) split len [ get print "." print ] for
 
nl "End " input</syntaxhighlight>
{{out}}
<pre>Hello.How.Are.You.Today.
End</pre>
 
=={{header|Kotlin}}==
{{works with|Kotlin|1.0b4}}
<syntaxhighlight lang="scala">fun main(args: Array<String>) {
val input = "Hello,How,Are,You,Today"
println(input.split(',').joinToString("."))
}</syntaxhighlight>
{{out}}
<pre>Hello.How.Are.You.Today</pre>
 
=={{header|Ksh}}==
<syntaxhighlight lang="ksh">
#!/bin/ksh
 
# Tokenize a string
 
# # Variables:
#
string="Hello,How,Are,You,Today"
inputdelim=\, # a comma
outputdelim=\. # a period
 
# # Functions:
#
# # Function _tokenize(str, indelim, outdelim)
#
function _tokenize {
typeset _str ; _str="$1"
typeset _ind ; _ind="$2"
typeset _outd ; _outd="$3"
while [[ ${_str} != ${_str/${_ind}/${_outd}} ]]; do
_str=${_str/${_ind}/${_outd}}
done
 
echo "${_str}"
}
 
######
# main #
######
 
_tokenize "${string}" "${inputdelim}" "${outputdelim}"</syntaxhighlight>
{{out}}<pre>Hello.How.Are.You.Today</pre>
 
=={{header|LabVIEW}}==
To tokenize the string, we use the Search/Split String function to split the string by its first comma. Add the beginning (up to, but not including the comma) to the end of the array, remove the first comma from the rest of the string, and pass it back through the shift register to the loop's next iteration. This is repeated until the string is empty. Printing is a simple matter of concatenation.<br/>
{{VI solution|LabVIEW_Tokenize_a_string.png}}
=={{header|Liberty BASIC}}==
<lang lb>'Note that Liberty Basic's array usage can reach element #10 before having to DIM the array
For i = 0 To 4
array$(i) = Word$("Hello,How,Are,You,Today", (i + 1), ",")
array$ = array$ + array$(i) + "."
Next i
 
=={{header|Lambdatalk}}==
Print Left$(array$, (Len(array$) - 1))</lang>
<syntaxhighlight lang="scheme">
{S.replace , by . in Hello,How,Are,You,Today}.
-> Hello.How.Are.You.Today.
</syntaxhighlight>
 
=={{header|Lang}}==
<syntaxhighlight lang="lang">
$str = Hello,How,Are,You,Today
fn.println(fn.join(\., fn.split($str, \,)))
</syntaxhighlight>
 
=={{header|Lang5}}==
<syntaxhighlight lang="lang5">'Hello,How,Are,You,Today ', split '. join .</syntaxhighlight>
 
=={{header|LDPL}}==
<syntaxhighlight lang="ldpl">
DATA:
explode/words is text vector
explode/index is number
explode/string is text
explode/length is number
explode/stringlength is number
explode/current-token is text
explode/char is text
explode/separator is text
i is number
PROCEDURE:
# Ask for a sentence
display "Enter a sentence: "
accept explode/string
 
# Declare explode Subprocedure
# Splits a text into a text vector by a certain delimiter
# Input parameters:
# - explode/string: the string to explode (destroyed)
# - explode/separator: the character used to separate the string (preserved)
# Output parameters:
# - explode/words: vector of splitted words
# - explode/length: length of explode/words
sub-procedure explode
join explode/string and explode/separator in explode/string
store length of explode/string in explode/stringlength
store 0 in explode/index
store 0 in explode/length
store "" in explode/current-token
while explode/index is less than explode/stringlength do
get character at explode/index from explode/string in explode/char
if explode/char is equal to explode/separator then
store explode/current-token in explode/words:explode/length
add explode/length and 1 in explode/length
store "" in explode/current-token
else
join explode/current-token and explode/char in explode/current-token
end if
add explode/index and 1 in explode/index
repeat
subtract 1 from explode/length in explode/length
end sub-procedure
 
# Separate the entered string
store " " in explode/separator
call sub-procedure explode
while i is less than or equal to explode/length do
display explode/words:i crlf
add 1 and i in i
repeat
</syntaxhighlight>
 
=={{header|LFE}}==
 
<syntaxhighlight lang="lisp">
> (set split (string:tokens "Hello,How,Are,You,Today" ","))
("Hello" "How" "Are" "You" "Today")
> (string:join split ".")
"Hello.How.Are.You.Today"
</syntaxhighlight>
 
=={{header|Lingo}}==
<syntaxhighlight lang="lingo">input = "Hello,How,Are,You,Today"
_player.itemDelimiter = ","
output = ""
repeat with i = 1 to input.item.count
put input.item[i]&"." after output
end repeat
delete the last char of output
put output
-- "Hello.How.Are.You.Today"</syntaxhighlight>
 
=={{header|Logo}}==
{{works with|UCB Logo}}
<langsyntaxhighlight lang="logo">to split :str :sep
output parse map [ifelse ? = :sep ["| |] [?]] :str
end</langsyntaxhighlight>
 
This form is more robust, doing the right thing if there are embedded spaces.
<langsyntaxhighlight lang="logo">to split :str :by [:acc []] [:w "||]
if empty? :str [output lput :w :acc]
ifelse equal? first :str :by ~
[output (split butfirst :str :by lput :w :acc)] ~
[output (split butfirst :str :by :acc lput first :str :w)]
end</langsyntaxhighlight>
 
<langsyntaxhighlight lang="logo">? show split "Hello,How,Are,You,Today ",
[Hello How Are You Today]</langsyntaxhighlight>
=={{header|Lua}}==
<lang lua>require"re"
 
=={{header|Logtalk}}==
record = re.compile[[
Using Logtalk built-in support for Definite Clause Grammars (DCGs) and representing the strings as atoms for readbility:
record <- ( <field> (',' <field>)* ) -> {} (%nl / !.)
<syntaxhighlight lang="logtalk">
field <- <escaped> / <nonescaped>
:- object(spliting).
nonescaped <- { [^,"%nl]* }
escaped <- '"' {~ ([^"] / '""' -> '"')* ~} '"'
]]
 
:- public(convert/2).
print(unpack(record:match"hello,how,are,you,today"))</lang>
:- mode(convert(+atom, -atom), one).
A different solution using the string-library of Lua: (skips empty columns)
<lang lua>str = "Hello,How,Are,You,Today"
 
convert(StringIn, StringOut) :-
tokens = {}
atom_chars(StringIn, CharactersIn),
for w in string.gmatch( str, "(%a+)" ) do
phrase(split(',', Tokens), CharactersIn),
tokens[#tokens+1] = w
phrase(split('.', Tokens), CharactersOut),
end
atom_chars(StringOut, CharactersOut).
 
split(Separator, [t([Character| Characters])| Tokens]) -->
for i = 1, #tokens do
[Character], {Character \== Separator}, split(Separator, [t(Characters)| Tokens]).
print( tokens[i] )
split(Separator, [t([])| Tokens]) -->
end</lang>
[Separator], split(Separator, Tokens).
split(_, [t([])]) -->
[].
% the look-ahead in the next rule prevents adding a spurious separator at the end
split(_, []), [Character] -->
[Character].
 
:- end_object.
e.g. to split a string with a delimiter of | AND allowing for empty values: (NOTE: This can probably be cleaned up)
</syntaxhighlight>
<lang lua>str = "Hello|How|Are|You||Today"
{{out}}
<pre>
| ?- spliting::convert('Hello,How,Are,You,Today', Converted).
Converted = 'Hello.How.Are.You.Today'
yes
</pre>
 
=={{header|Lua}}==
tokens = {}
Split function callously stolen from the lua-users wiki
for w in string.gmatch( str, "([^|]*)|?" ) do
<syntaxhighlight lang="lua">function string:split (sep)
tokens[#tokens+1] = w
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
self:gsub(pattern, function(c) fields[#fields+1] = c end)
return fields
end
table.remove(tokens)--pops off the last empty value, because without doing |? we lose the last element.
 
local str = "Hello,How,Are,You,Today"
for i = 1, #tokens do
print(table.concat(str:split(","), "."))</syntaxhighlight>
print( tokens[i] )
{{out}}
end</lang>
<pre>Hello.How.Are.You.Today</pre>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
Module CheckIt {
Function Tokenize$(s){
\\ letter$ pop a string from stack of values
\\ shift 2 swap top two values on stack of values
fold1=lambda m=1 ->{
shift 2 :if m=1 then m=0:drop: push letter$ else push letter$+"."+letter$
}
=s#fold$(fold1)
}
Print Tokenize$(piece$("Hello,How,Are,You,Today",",")) ="Hello.How.Are.You.Today" ' true
}
Checkit
</syntaxhighlight>
 
=={{header|M4}}==
<langsyntaxhighlight M4lang="m4">define(`s',`Hello,How,Are,You,Today')
define(`set',`define(`$1[$2]',`$3')')
define(`get',`defn($1[$2])')
Line 814 ⟶ 2,470:
define(`show',
`ifelse(eval(j<n),1,`get(a,j).`'define(`j',incr(j))`'show')')
show</langsyntaxhighlight>
 
{{out}}
Output:
<pre>
Hello.How.Are.You.Today.
</pre>
 
=={{header|MathematicaMaple}}==
<langsyntaxhighlight Mathematicalang="maple">Row[Riffle[StringSplit[StringTools:-Join(StringTools:-Split("Hello,How,Are,You,Today", ","]), "."]]);</langsyntaxhighlight>
{{Out|Output}}
<pre>"Hello.How.Are.You.Today"</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">StringJoin@StringSplit["Hello,How,Are,You,Today", "," -> "."]</syntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
<syntaxhighlight lang="matlab">
<lang MATLAB>function tokenizeString(string,delimeter)
s=strsplit('Hello,How,Are,You,Today',',')
fprintf(1,'%s.',s{:})
</syntaxhighlight>
 
{{out}}
tokens = {};
<pre>
Hello.How.Are.You.Today.
while not(isempty(string))
</pre>
[tokens{end+1},string] = strtok(string,delimeter);
end
for i = (1:numel(tokens)-1)
fprintf([tokens{i} '.'])
end
fprintf([tokens{end} '\n'])
end</lang>
 
=={{header|Maxima}}==
Output:
<syntaxhighlight lang MATLAB>>="maxima">l: tokenizeStringsplit('"Hello,How,Are,You,Today'",' ",'")$
printf(true, "~{~a~^.~}~%", l)$</syntaxhighlight>
Hello.How.Are.You.Today</lang>
 
A slightly different way
<syntaxhighlight lang="maxima">
split("Hello,How,Are,You,Today",",")$
simplode(%,".");
</syntaxhighlight>
{{out}}
<pre>
"Hello.How.Are.You.Today"
</pre>
 
=={{header|MAXScript}}==
<langsyntaxhighlight lang="maxscript">output = ""
for word in (filterString "Hello,How,Are,You,Today" ",") do
(
output += (word + ".")
)
format "%\n" output</langsyntaxhighlight>
 
=={{header|Mercury}}==
<syntaxhighlight lang="text">
:- module string_tokenize.
:- interface.
Line 864 ⟶ 2,532:
Tokens = string.split_at_char((','), "Hello,How,Are,You,Today"),
io.write_list(Tokens, ".", io.write_string, !IO),
io.nl(!IO).</langsyntaxhighlight>
 
=={{header|min}}==
{{works with|min|0.19.3}}
<syntaxhighlight lang="min">"Hello,How,Are,You,Today" "," split "." join print</syntaxhighlight>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">tokens = "Hello,How,Are,You,Today".split(",")
print tokens.join(".")</syntaxhighlight>
 
=={{header|MMIX}}==
<langsyntaxhighlight lang="mmix">sep IS ','
EOS IS 0
NL IS 10
Line 920 ⟶ 2,596:
LDBU t,tp
PBNZ t,2B % UNTIL EOB(uffer)
TRAP 0,Halt,0</langsyntaxhighlight>
{{out}}
Output:
<pre>
~/MIX/MMIX/Progs> mmix tokenizing
Hello
Line 928 ⟶ 2,605:
You
Today
</pre>
 
=={{header|Modula-3}}==
<langsyntaxhighlight lang="modula3">MODULE Tokenize EXPORTS Main;
 
IMPORT IO, TextConv;
Line 947 ⟶ 2,625:
END;
IO.Put("\n");
END Tokenize.</langsyntaxhighlight>
 
=={{header|MUMPS}}==
<langsyntaxhighlight MUMPSlang="mumps">TOKENS
NEW I,J,INP
SET INP="Hello,how,are,you,today"
Line 955 ⟶ 2,634:
NEW J FOR J=1:1:I WRITE INP(J) WRITE:J'=I "."
KILL I,J,INP // Kill is optional. "New" variables automatically are killed on "Quit"
QUIT</langsyntaxhighlight>
 
In use:
USER>D TOKENS^ROSETTA
Hello.how.are.you.today
 
=={{header|Nanoquery}}==
<syntaxhighlight lang="nanoquery">for word in "Hello,How,Are,You,Today".split(",")
print word + "."
end</syntaxhighlight>
{{out}}
<pre>Hello.How.Are.You.Today.</pre>
 
=={{header|Nemerle}}==
<langsyntaxhighlight Nemerlelang="nemerle">using System;
using System.Console;
using Nemerle.Utility.NString;
Line 975 ⟶ 2,661:
// a quick in place list comprehension takes care of that
}
}</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">/*NetRexx program *****************************************************
* 20.08.2012 Walter Pachl derived from REXX Version 3
**********************************************************************/
Line 989 ⟶ 2,675:
Say ss.word(i)'.'
End
Say 'End-of-list.'</langsyntaxhighlight>
Output as in REXX version
 
=={{header|NewLISP}}==
<syntaxhighlight lang="newlisp">(print (join (parse "Hello,How,Are,You,Today" ",") "."))</syntaxhighlight>
 
=={{header|Nial}}==
 
Example for <b>Q'Nial7</b>, using <code>set "nodecor</code> and <code>set "diagram</code> switches for better display of the array structure:
 
Define Array with input string:
 
<syntaxhighlight lang="nial"> s := 'Hello,How,Are,You,Today'
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|H|e|l|l|o|,|H|o|w|,|A|r|e|,|Y|o|u|,|T|o|d|a|y|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</syntaxhighlight>
 
Split string at the commas:
 
<syntaxhighlight lang="nial"> t := s eachall = `, cut s
+-----------+-------+-------+-------+-----------+
|+-+-+-+-+-+|+-+-+-+|+-+-+-+|+-+-+-+|+-+-+-+-+-+|
||H|e|l|l|o|||H|o|w|||A|r|e|||Y|o|u|||T|o|d|a|y||
|+-+-+-+-+-+|+-+-+-+|+-+-+-+|+-+-+-+|+-+-+-+-+-+|
+-----------+-------+-------+-------+-----------+</syntaxhighlight>
 
Join string with <code>.</code> and remove last <code>.</code>
 
<syntaxhighlight lang="nial"> u := front content (cart t `.)
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|H|e|l|l|o|.|H|o|w|.|A|r|e|.|Y|o|u|.|T|o|d|a|y|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</syntaxhighlight>
 
Less cluttered display, using <code>set "sketch;set "nodecor</code> display switches.
 
<syntaxhighlight lang="nial"> s:='Hello,How,Are,You,Today'
Hello,How,Are,You,Today
t:= s eachall = `, cut s
+-----+---+---+---+-----+
|Hello|How|Are|You|Today|
+-----+---+---+---+-----+
u:=front content (cart t `.)
 
Hello.How.Are.You.Today</syntaxhighlight>
 
Or as a one-liner:
 
<syntaxhighlight lang="nial">
front content (cart (s eachall = `, cut s) `.)
</syntaxhighlight>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">import strutils
 
let text = "Hello,How,Are,You,Today"
let tokens = text.split(',')
echo tokens.join(".")</syntaxhighlight>
 
{{out}}
<pre>Hello.How.Are.You.Today</pre>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">
class Parse {
bundle Default {
function : Main(args : String[]) ~ Nil {
class Parse {
tokens := "Hello,How,Are,You,Today"->Split(",");
function : Main(args : String[]) ~ Nil {
each(i : tokens) := "Hello,How,Are,You,Today"->Split(",");{
each(i : tokens[i]->PrintLine() {;
};
tokens[i]->PrintLine();
};
}
}
}</syntaxhighlight>
}
</lang>
 
=={{header|Objective-C}}==
Line 1,011 ⟶ 2,752:
{{works with|Cocoa}}
 
<langsyntaxhighlight lang="objc">NSString *text = @"Hello,How,Are,You,Today";
NSArray *tokens = [text componentsSeparatedByString:@","];
NSString *result = [tokens componentsJoinedByString:@"."];
NSLog(result);</langsyntaxhighlight>
 
=={{header|OCaml}}==
To split on a single-character separator:
<syntaxhighlight lang="ocaml">let words = String.split_on_char ',' "Hello,How,Are,You,Today" in
<lang ocaml>let rec split_char sep str =
String.concat "." words
try
</syntaxhighlight>
let i = String.index str sep in
String.sub str 0 i ::
split_char sep (String.sub str (i+1) (String.length str - i - 1))
with Not_found ->
[str]</lang>
 
The function split_on_char has been introduced in OCaml 4.04. In previous versions, it could be implemented by:
Or the [[:Category:Recursion|tail-recursive]] equivalent:
 
<syntaxhighlight lang="ocaml">let split_on_char sep s =
<lang ocaml>(* [try .. with] structures break tail-recursion,
let r = ref [] in
so we externalise it in a sub-function *)
let j = ref (String.length s) in
let string_index str c =
tryfor i = Some(String.indexlength s - 1 downto str0 c)do
if s.[i] = sep then begin
with Not_found -> None
r := String.sub s (i + 1) (!j - i - 1) :: !r;
j := i
end
done;
String.sub s 0 !j :: !r</syntaxhighlight>
 
=={{header|Oforth}}==
let split_char sep str =
let rec aux acc str =
match string_index str sep with
| Some i ->
let this = String.sub str 0 i
and next = String.sub str (i+1) (String.length str - i - 1) in
aux (this::acc) next
| None ->
List.rev(str::acc)
in
aux [] str
;;</lang>
 
<syntaxhighlight lang="oforth">"Hello,How,Are,You,Today" wordsWith(',') println</syntaxhighlight>
But both of these will process extraneous String.sub (so one string alloc) to generate the "rest of the string" each time to pass to the next call. For N tokens there will be (N - 2) unneeded allocs. To resolve this here is a version which keeps track of the index in the string we will look next:
 
{{out}}
<lang ocaml>let split_char sep str =
<pre>
let string_index_from i =
[Hello, How, Are, You, Today]
try Some (String.index_from str i sep)
</pre>
with Not_found -> None
in
let rec aux i acc = match string_index_from i with
| Some i' ->
let w = String.sub str i (i' - i) in
aux (succ i') (w::acc)
| None ->
let w = String.sub str i (String.length str - i) in
List.rev (w::acc)
in
aux 0 []</lang>
 
=={{header|ooRexx}}==
Splitting on a string separator using the regular expressions library:
<syntaxhighlight lang="oorexx">text='Hello,How,Are,You,Today'
<lang ocaml>#load "str.cma";;
do while text \= ''
let split_str sep str =
parse var text word1 ',' text
Str.split (Str.regexp_string sep) str</lang>
call charout 'STDOUT:',word1'.'
 
end</syntaxhighlight>
There is already a library function for joining:
{{out}}
<lang ocaml>String.concat sep strings</lang>
<pre>Hello.How.Are.You.Today.</pre>
 
=={{header|OpenEdge/Progress}}==
<langsyntaxhighlight lang="progress">FUNCTION tokenizeString RETURNS CHAR (
i_c AS CHAR
):
Line 1,096 ⟶ 2,818:
MESSAGE
tokenizeString( "Hello,How,Are,You,Today" )
VIEW-AS ALERT-BOX.</langsyntaxhighlight>
{{out}}
Output:
<pre>
---------------------------
Message
Line 1,105 ⟶ 2,828:
OK
---------------------------
</pre>
 
=={{header|Oz}}==
<langsyntaxhighlight lang="oz">for T in {String.tokens "Hello,How,Are,You,Today" &,} do
{System.printInfo T#"."}
end</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
===Version #1.===
Simple version, like the most custom ones here (for this task). This version has 1 character delimiter,
which is not allowed in the beginning and at the end of string, in addition, double, triple, etc., delimiters
are not allowed too.
 
{{Works with|PARI/GP|2.7.4 and above}}
 
<syntaxhighlight lang="parigp">
\\ Tokenize a string str according to 1 character delimiter d. Return a list of tokens.
\\ Using ssubstr() from http://rosettacode.org/wiki/Substring#PARI.2FGP
\\ tokenize() 3/5/16 aev
tokenize(str,d)={
my(str=Str(str,d),vt=Vecsmall(str),d1=sasc(d),Lr=List(),sn=#str,v1,p1=1);
for(i=p1,sn, v1=vt[i]; if(v1==d1, listput(Lr,ssubstr(str,p1,i-p1)); p1=i+1));
return(Lr);
}
 
{
\\ TEST
print(" *** Testing tokenize from Version #1:");
print("1.", tokenize("Hello,How,Are,You,Today",","));
\\ BOTH 2 & 3 are NOT OK!!
print("2.",tokenize("Hello,How,Are,You,Today,",","));
print("3.",tokenize(",Hello,,How,Are,You,Today",","));
}
</syntaxhighlight>
 
{{Output}}
<pre>
*** Testing tokenize from Version #1:
1.List(["Hello", "How", "Are", "You", "Today"])
2.List(["Hello", "How", "Are", "You", "Today", ","])
3.List([",Hello,,How,Are,You,Today,", "Hello", ",How,Are,You,Today,", "How", "Ar
e", "You", "Today"])
</pre>
 
===Version #2.===
Advanced version. Delimiter is allowed in any place. In addition, multiple delimiters are allowed too.
This is really useful for considering omitted data.
This version can be used for positional parameters processing, or for processing data from tables with string rows.
 
{{Works with|PARI/GP|2.7.4 and above}}
 
<syntaxhighlight lang="parigp">
\\ Tokenize a string str according to 1 character delimiter d. Return a list of tokens.
\\ Using ssubstr() from http://rosettacode.org/wiki/Substring#PARI.2FGP
\\ stok() 3/5/16 aev
stok(str,d)={
my(d1c=ssubstr(d,1,1),str=Str(str,d1c),vt=Vecsmall(str),d1=sasc(d1c),
Lr=List(),sn=#str,v1,p1=1,vo=32);
if(sn==1, return(List(""))); if(vt[sn-1]==d1,sn--);
for(i=1,sn, v1=vt[i];
if(v1!=d1, vo=v1; next);
if(vo==d1||i==1, listput(Lr,""); p1=i+1; vo=v1; next);
if(i-p1>0, listput(Lr,ssubstr(str,p1,i-p1)); p1=i+1);
vo=v1;
);
return(Lr);
}
 
{
\\ TEST
print(" *** Testing stok from Version #2:");
\\ pp - positional parameter(s)
print("1. 5 pp: ", stok("Hello,How,Are,You,Today",","));
print("2. 5 pp: ", stok("Hello,How,Are,You,Today,",","));
print("3. 9 pp: ", stok(",,Hello,,,How,Are,You,Today",","));
print("4. 6 pp: ", stok(",,,,,,",","));
print("5. 1 pp: ", stok(",",","));
print("6. 1 pp: ", stok("Hello-o-o??",","));
print("7. 0 pp: ", stok("",","));
}
</syntaxhighlight>
 
{{Output}}
<pre>
*** Testing stok from Version #2:
1. 5 pp: List(["Hello", "How", "Are", "You", "Today"])
2. 5 pp: List(["Hello", "How", "Are", "You", "Today"])
3. 9 pp: List(["", "", "Hello", "", "", "How", "Are", "You", "Today"])
4. 6 pp: List(["", "", "", "", "", ""])
5. 1 pp: List([""])
6. 1 pp: List(["Hello-o-o??"])
7. 0 pp: List([""])
</pre>
 
=={{header|Pascal}}==
{{works with|Free_Pascal}}
<langsyntaxhighlight lang="pascal">program TokenizeString;
 
{$mode objfpc}{$H+}
 
uses
SysUtils, Classes;
const
CHelloStrTestString = 'Hello,How,Are,You,Today';
var
Tokens: TStringList;
I: Integer;
VResult: string = '';
begin
// Uses FCL facilities, "harder" algorithm not implemented
for I := 1 to Length(CHelloStr) do
Tokens := TStringList.Create;
if CHelloStr[I] = ',' then
try
VResult += LineEnding
Tokens.Delimiter := ',';
else
Tokens.DelimitedText := TestString;
VResult += CHelloStr[I];
Tokens.Delimiter := '.'; // For example
WriteLn(VResult);
// To standard Output
end.</lang>
WriteLn(Format('Tokenize from: "%s"', [TestString]));
WriteLn(Format('to: "%s"',[Tokens.DelimitedText]));
finally
Tokens.Free;
end;
end.</syntaxhighlight>
 
The result is:
Tokenize from: "Hello,How,Are,You,Today"
Hello
to: "Hello.How.Are.You.Today"
How
Are
You
Today
'''Credits''': [http://code.google.com/p/lazsolutions/ silvioprog], 15:10, 8 January 2012 (UTC)
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">print join('.', split /,/, 'Hello,How,Are,You,Today'), "\n";</langsyntaxhighlight>
CLI one-liner form:
<syntaxhighlight lang="perl">echo "Hello,How,Are,You,Today" | perl -aplF/,/ -e '$" = "."; $_ = "@F";'</syntaxhighlight>
which is a compact way of telling Perl to do
<syntaxhighlight lang="perl">BEGIN { $/ = "\n"; $\ = "\n"; }
LINE: while (defined($_ = <ARGV>)) {
chomp $_;
our(@F) = split(/,/, $_, 0);
$" = '.';
$_ = "@F";
}
continue {
die "-p destination: $!\n" unless print $_;
}</syntaxhighlight>
 
=={{header|Perl 6Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
{{works with|Rakudo|#22 "Thousand Oaks"}}
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Hello,How,Are,You,Today"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">","</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"."</span><span style="color: #0000FF;">)</span>
<lang perl6>'Hello,How,Are,You,Today'.split(',').join('.').say;</lang>
<!--</syntaxhighlight>-->
{{Out}}
<pre>
"Hello.How.Are.You.Today"
</pre>
 
=={{header|Phixmonti}}==
<syntaxhighlight lang="phixmonti">/# "Hello,How,Are,You,Today" "," "." subst print #/
"Hello,How,Are,You,Today" "," " " subst split len for get print "." print endfor</syntaxhighlight>
 
=={{header|PHP}}==
{{works with|PHP|5.x}}
 
<langsyntaxhighlight lang="php"><?php
$str = 'Hello,How,Are,You,Today';
echo implode('.', explode(',', $str));
?></langsyntaxhighlight>
 
=={{header|Picat}}==
Using the built-in functions <code>split/2</code> and <code>join/2</code>.
<syntaxhighlight lang="picat">import util.
 
go =>
S = "Hello,How,Are,You,Today",
T = S.split(","),
println(T),
T.join(".").println(),
 
% As a one liner:
S.split(",").join(".").println().</syntaxhighlight>
 
{{out}}
<pre>[Hello,How,Are,You,Today]
Hello.How.Are.You.Today
Hello.How.Are.You.Today</pre>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(mapcar pack
(split (chop "Hello,How,Are,You,Today") ",") )</langsyntaxhighlight>
 
=={{header|Pike}}==
<langsyntaxhighlight lang="pike">("Hello,How,Are,You,Today" / ",") * ".";</langsyntaxhighlight>
 
=={{header|PL/I}}==
<syntaxhighlight lang="pli">tok: Proc Options(main);
<lang PL/I>
declare s character (100) initial ('Hello,How,Are,You,Today');
declare n fixed binary (31);
Line 1,184 ⟶ 3,039:
put skip list (string(table));
end;
end;</syntaxhighlight>
</lang>
{{out}}
<pre>Hello.How.Are.You.Today</pre>
 
=={{header|PL/M}}==
<syntaxhighlight lang="plm">100H:
/* CP/M CALLS */
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;
 
/* SPLIT A STRING ON CHARACTER 'SEP'.
THE 'PARTS' ARRAY WILL CONTAIN POINTERS TO THE START OF EACH ELEMENT.
THE AMOUNT OF PARTS IS RETURNED.
*/
TOKENIZE: PROCEDURE (SEP, STR, PARTS) ADDRESS;
DECLARE SEP BYTE, (STR, PARTS) ADDRESS;
DECLARE (N, P BASED PARTS) ADDRESS;
DECLARE CH BASED STR BYTE;
N = 0;
LOOP:
P(N) = STR;
N = N + 1;
DO WHILE CH <> '$' AND CH <> SEP;
STR = STR + 1;
END;
IF CH = '$' THEN RETURN N;
CH = '$';
STR = STR + 1;
GO TO LOOP;
END TOKENIZE;
 
/* TEST ON THE GIVEN INPUT */
DECLARE HELLO (24) BYTE INITIAL ('HELLO,HOW,ARE,YOU,TODAY$');
DECLARE PARTS (10) ADDRESS;
DECLARE (I, LEN) ADDRESS;
 
LEN = TOKENIZE(',', .HELLO, .PARTS);
DO I = 0 TO LEN-1;
CALL PRINT(PARTS(I));
CALL PRINT(.'. $');
END;
 
CALL EXIT;
EOF;</syntaxhighlight>
{{out}}
<pre>HELLO. HOW. ARE. YOU. TODAY. </pre>
 
=={{header|Plain English}}==
<syntaxhighlight lang="plainenglish">To run:
Start up.
Split "Hello,How,Are,You,Today" into some string things given the comma byte.
Join the string things with the period byte giving a string.
Destroy the string things.
Write the string on the console.
Wait for the escape key.
Shut down.
 
To join some string things with a byte giving a string:
Get a string thing from the string things.
Loop.
If the string thing is nil, exit.
Append the string thing's string to the string.
If the string thing's next is not nil, append the byte to the string.
Put the string thing's next into the string thing.
Repeat.</syntaxhighlight>
{{out}}
<pre>
Hello.How.Are.You.Today
</pre>
 
=={{header|Pop11}}==
Line 1,193 ⟶ 3,117:
First show the use of sysparse_string to break up a string and make a list of strings.
 
<langsyntaxhighlight lang="pop11">;;; Make a list of strings from a string using space as separator
lvars list;
sysparse_string('the cat sat on the mat') -> list;
;;; print the list of strings
list =>
** [the cat sat on the mat]</langsyntaxhighlight>
 
By giving it an extra parameter 'true' we can make it recognize numbers and produce a list of strings and numbers
 
<langsyntaxhighlight lang="pop11">lvars list;
sysparse_string('one 1 two 2 three 3 four 4', true) -> list;
;;; print the list of strings and numbers
Line 1,211 ⟶ 3,135:
** <true>
isinteger(list(2))=>
** <true></langsyntaxhighlight>
 
Now show some uses of the built in procedure sys_parse_string, which allows more options:
 
<langsyntaxhighlight lang="pop11">;;; Make pop-11 print strings with quotes
true -> pop_pr_quotes;
;;;
Line 1,229 ⟶ 3,153:
;;; print the list of strings
strings =>
** ['Hello' 'How' 'Are' 'You' 'Today']</langsyntaxhighlight>
 
If {% ... %} were used instead of [% ... %] the result would be
a vector (i.e. array) of strings rather than a list of strings.
 
<langsyntaxhighlight lang="pop11">{% sys_parse_string(str, `,`) %} -> strings;
;;; print the vector
strings =>
** {'Hello' 'How' 'Are' 'You' 'Today'}</langsyntaxhighlight>
It is also possible to give sys_parse_string a 'conversion' procedure, which is applied to each of the tokens.
E.g. it could be used to produce a vector of numbers, using the conversion procedure 'strnumber', which converts a string to a number:
 
<langsyntaxhighlight lang="pop11">lvars numbers;
{% sys_parse_string('100 101 102 103 99.9 99.999', strnumber) %} -> numbers;
;;; the result is a vector containing integers and floats,
;;; which can be printed thus:
numbers =>
** {100 101 102 103 99.9 99.999}</langsyntaxhighlight>
 
Using lower level pop-11 facilities to tokenise the string:
 
<langsyntaxhighlight lang="pop11">;;; Declare and initialize variables
lvars str='Hello,How,Are,You,Today';
;;; Iterate over string
Line 1,268 ⟶ 3,192:
endif;
;;; Reverse the list
rev(ls) -> ls;</langsyntaxhighlight>
 
Since the task requires to use array we convert list to array
 
<langsyntaxhighlight lang="pop11">;;; Put list elements and lenght on the stack
destlist(ls);
;;; Build a vector from them
Line 1,280 ⟶ 3,204:
printf(ar(i), '%s.');
endfor;
printf('\n');</langsyntaxhighlight>
 
We could use list directly for printing:
 
<langsyntaxhighlight lang="pop11">for i in ls do
printf(i, '%s.');
endfor;</langsyntaxhighlight>
 
so the conversion to vector is purely to satisfy task formulation.
 
=={{header|PowerBASIC}}==
 
PowerBASIC has a few keywords that make parsing strings trivial: <code>PARSE</code>, <code>PARSE$</code>, and <code>PARSECOUNT</code>. (<code>PARSE$</code>, not shown here, is for extracting tokens one at a time, while <code>PARSE</code> extracts all tokens at once into an array. <code>PARSECOUNT</code> returns the number of tokens found.)
 
<lang powerbasic>FUNCTION PBMAIN () AS LONG
DIM parseMe AS STRING
parseMe = "Hello,How,Are,You,Today"
 
REDIM parsed(PARSECOUNT(parseMe) - 1) AS STRING
PARSE parseMe, parsed() 'comma is default delimiter
 
DIM L0 AS LONG, outP AS STRING
outP = parsed(0)
FOR L0 = 1 TO UBOUND(parsed) 'could reuse parsecount instead of ubound
outP = outP & "." & parsed(L0)
NEXT
 
MSGBOX outP
END FUNCTION</lang>
 
=={{header|PowerShell}}==
{{works with|PowerShell|1}}
<langsyntaxhighlight lang="powershell">$words = "Hello,How,Are,You,Today".Split(',')
[string]::Join('.', $words)</langsyntaxhighlight>
 
{{works with|PowerShell|2}}
<langsyntaxhighlight lang="powershell">$words = "Hello,How,Are,You,Today" -split ','
$words -join '.'</langsyntaxhighlight>
 
{{works with|PowerShell|2}}
The StringSplitOptions enumeration weeds out the return of empty elements.
<syntaxhighlight lang="powershell">
"Hello,How,Are,You,Today", ",,Hello,,Goodbye,," | ForEach-Object {($_.Split(',',[StringSplitOptions]::RemoveEmptyEntries)) -join "."}
</syntaxhighlight>
{{Out}}
<pre>
Hello.How.Are.You.Today
Hello.Goodbye
</pre>
 
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<langsyntaxhighlight lang="prolog">splitup(Sep,[token(B)|BL]) --> splitup(Sep,B,BL).
splitup(Sep,[A|AL],B) --> [A], {\+ [A] = Sep }, splitup(Sep,AL,B).
splitup(Sep,[],[B|BL]) --> Sep, splitup(Sep,B,BL).
Line 1,330 ⟶ 3,244:
phrase(splitup(".",Tokens),Backtogether),
string_to_list(ABack,Backtogether),
writeln(ABack).</langsyntaxhighlight>
{{out}}
Output:
<pre>
?- start.
Hello.How.Are.You.Today
</pre>
 
{{works with|SWI Prolog 7}}
=={{header|PureBasic}}==
 
Using the SWI Prolog string data type and accompanying predicates,
'''As described
this can be accomplished in a few lines in the top level:
<lang PureBasic>NewList MyStrings.s()
 
<syntaxhighlight lang="prolog">
For i=1 To 5
?- split_string("Hello,How,Are,You,Today", ",", "", Split),
AddElement(MyStrings())
| atomics_to_string(Split, ".", PeriodSeparated),
MyStrings()=StringField("Hello,How,Are,You,Today",i,",")
| writeln(PeriodSeparated).
Next i
Hello.How.Are.You.Today
 
</syntaxhighlight>
ForEach MyStrings()
Print(MyStrings()+".")
Next</lang>
 
'''Still, easier would be
<lang PureBasic>Print(ReplaceString("Hello,How,Are,You,Today",",","."))</lang>
 
=={{header|Python}}==
{{works with|Python|2.5}}{{works with|Python|3.0}}
 
<langsyntaxhighlight lang="python">text = "Hello,How,Are,You,Today"
tokens = text.split(',')
print ('.'.join(tokens))</langsyntaxhighlight>
 
Or if interpretation of the task description means you don't need to keep an intermediate array:
<langsyntaxhighlight lang="python">print ('.'.join('Hello,How,Are,You,Today'.split(',')))</langsyntaxhighlight>
 
=={{header|Q}}==
<syntaxhighlight lang="q">words: "," vs "Hello,How,Are,You,Today"
"." sv words</syntaxhighlight>
 
{{out}}
<pre>"Hello.How.Are.You.Today"</pre>
 
=={{header|QB64}}==
''CBTJD'': 2020/03/12
<syntaxhighlight lang="vb">a$ = "Hello,How,Are,You,Today" ' | Initialize original string.
FOR na = 1 TO LEN(a$) ' | Start loop to count number of commas.
IF MID$(a$, na, 1) = "," THEN nc = nc + 1 ' | For each comma, increment nc.
NEXT ' | End of loop.
DIM t$(nc) ' | Dim t$ array with total number of commas (nc). Array base is 0.
FOR nb = 1 TO LEN(a$) ' | Start loop to find each word.
c$ = MID$(a$, nb, 1) ' | Look at each character in the string.
IF c$ = "," THEN ' | If the character is a comma, increase the t$ array for the next word.
t = t + 1 ' | t = token word count. Starts at 0 because array base is 0.
ELSE ' | Or...
t$(t) = t$(t) + c$ ' | Add each character to the current token (t$) word.
END IF ' | End of decision tree.
NEXT ' | End of loop.
FOR nd = 0 TO t ' | Start loop to create final desired output.
tf$ = tf$ + t$(nd) + "." ' | Add each token word from t$ followed by a period to the final tf$.
NEXT ' | End of loop.
PRINT LEFT$(tf$, LEN(tf$) - 1) ' | Print all but the last period of tf$.
END ' | Program end.
</syntaxhighlight>
 
'''Alternative method using word$ function:'''
----
''CBTJD'': 2020/03/12
<syntaxhighlight lang="vb">a$ = "Hello,How,Are,You,Today" ' | Initialize original string.
DIM t$(LEN(a$) / 2) ' | Create an overestimated sized array.
FOR nd = 1 TO LEN(a$) ' | Start loop to find each comma.
IF MID$(a$, nd, 1) = "," THEN ' | If a comma is found...
tc = tc + 1 ' | Increment tc for each found comma.
t$(tc) = word$(a$, tc, ",") ' | Assign tc word to t$(tc) array.
END IF ' | End decision tree.
NEXT ' | End loop.
t$(tc + 1) = word$(a$, tc + 1, ",") ' | Assign last word to next array position.
ft$ = t$(1) ' | Start final return string ft$ with first array value.
FOR ne = 2 TO tc + 1 ' | Start loop to add periods and array values.
ft$ = ft$ + "." + t$(ne) ' | Concatenate a period with subsequent array values.
NEXT ' | End loop.
PRINT ft$ ' | Print final return string ft$.
 
FUNCTION word$ (inSTG$, inDEC, inPRM$) ' | word$ function accepts original string, word number, and separator.
inSTG$ = inSTG$ + inPRM$ ' | Add a separator to the end of the original string.
FOR na = 1 TO LEN(inSTG$) ' | Start loop to count total number of separators.
IF MID$(inSTG$, na, 1) = inPRM$ THEN nc = nc + 1 ' | If separator found, increment nc.
NEXT ' | End loop.
IF inDEC > nc THEN word$ = "": GOTO DONE ' | If requested word number (inDEC) is greater than total words (nc), bail.
FOR nd = 1 TO inDEC ' | Start loop to find requested numbered word.
last = st ' | Remember the position of the last separator.
st = INSTR(last + 1, inSTG$, inPRM$) ' | Find the next separator.
NEXT ' | End loop.
word$ = MID$(inSTG$, last + 1, st - last - 1) ' | Return requested word.
DONE: ' | Label for bail destination of word count error check.
END FUNCTION ' | End of function.
</syntaxhighlight>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="quackery"> [ [] [] rot
witheach
[ dup char , = iff
[ drop nested join [] ]
else join ]
nested join ] is tokenise ( $ --> [ )
[ witheach [ echo$ say "." ] ] is display ( [ --> )
$ "Hello,How,Are,You,Today" tokenise display</syntaxhighlight>
 
{{Out}}
 
<pre>Hello.How.Are.You.Today.</pre>
 
=={{header|R}}==
<langsyntaxhighlight Rlang="r">text <- "Hello,How,Are,You,Today"
junk <- strsplit(text, split=",")
print(paste(unlist(junk), collapse="."))</langsyntaxhighlight>
 
or the one liner
 
<langsyntaxhighlight Rlang="r">paste(unlist(strsplit(text, split=",")), collapse=".")</langsyntaxhighlight>
 
=={{header|Racket}}==
 
<syntaxhighlight lang="racket">
#lang racket
(string-join (string-split "Hello,How,Are,You,Today" ",") ".")
;; -> "Hello.How.Are.You.Today"
</syntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|#22 "Thousand Oaks"}}
<syntaxhighlight lang="raku" line>'Hello,How,Are,You,Today'.split(',').join('.').say;</syntaxhighlight>
 
Or with function calls:
 
<syntaxhighlight lang="raku" line>say join '.', split ',', 'Hello,How,Are,You,Today';</syntaxhighlight>
 
=={{header|Raven}}==
<langsyntaxhighlight lang="raven">'Hello,How,Are,You,Today' ',' split '.' join print</langsyntaxhighlight>
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">print ["Original:" original: "Hello,How,Are,You,Today"]
tokens: parse original ","
dotted: "" repeat i tokens [append dotted rejoin [i "."]]
print ["Dotted: " dotted]</langsyntaxhighlight>
 
{{out}}
Output:
<pre>
Original: Hello,How,Are,You,Today
Dotted: Hello.How.Are.You.Today.
</pre>
 
=={{header|Red}}==
<syntaxhighlight lang="red">str: "Hello,How,Are,You,Today"
>> tokens: split str ","
>> probe tokens
["Hello" "How" "Are" "You" "Today"]
 
>> periods: replace/all form tokens " " "." ;The word FORM converts the list series to a string removing quotes.
>> print periods ;then REPLACE/ALL spaces with period
Hello.How.Are.You.Today</syntaxhighlight>
 
=={{header|Retro}}==
<syntaxhighlight lang="retro">{{
<lang Retro>{{
: char ( -$ ) " " ;
: tokenize ( $-$$ )
Line 1,397 ⟶ 3,416:
[ tokenize action dup 1 <> ] while drop
^buffer'get drop ;
}}</langsyntaxhighlight>
 
This will suffice to split a string into an array of substrings. It is used like this:
 
<langsyntaxhighlight Retrolang="retro">create strings 100 allot
"Hello,How,Are,You,Today" ', strings split</langsyntaxhighlight>
 
Since the buffer' vocabulary creates a zero-terminated buffer, we can display it using the each@ combinator and a simple quote:
 
<langsyntaxhighlight Retrolang="retro">strings [ @ "%s." puts ] ^types'STRING each@</langsyntaxhighlight>
 
=={{header|REXX}}==
===version 1===
This REXX version doesn't append a period to the last word in the list.
<lang rexx>/*REXX pgm separates a string of comma─delimited words ──► array; echos.*/
<syntaxhighlight lang="rexx">/*REXX program separates a string of comma─delimited words, and echoes them ──► terminal*/
sss='Hello,How,Are,You,Today' /*words seperated by commas (,). */
sayoriginal 'input= string ='Hello,How,Are,You,Today' sss /*some words separated /*displayby thecommas original string(,). */
new=sss say 'The input string:' original /*makedisplay aoriginal copystring of──► the stringterminal. */
new= original do items=1 until new=='' /*keepmake goinga untilcopy SSSof isthe emptystring. */
parse var new a.items do #=1 until new==',' new /*parsekeep processing until wordsNEW delinated byis commaempty.*/
parse var new @.# ',' new /*parse words delineated by a comma (,)*/
end /*items*/
end /*#*/ /* [↑] the new array is named @. */
 
say; say 'Words in the string:' /*Display aNEW header foris thedestructively listparsed. [↑] */
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(' End─of─list ', 40, "═") /*display a (EOL) trailer for the list.*/</syntaxhighlight>
{{out|output|text=&nbsp; when using the internal default input:}}
<pre>
The input string: Hello,How,Are,You,Today
 
═════════ Words in the string ══════════
do k=1 for items /*Now, display all the words. */
say a.k'.' /*append a period to the word. */
end /*k*/
say 'End-of-list.' /*Display a trailer for the list.*/</lang>
'''output'''
<pre style="overflow:scroll">
input string = Hello,How,Are,You,Today
Words in the string:
Hello.
How.
Are.
You.
Today.
═════════════ End─of─list ══════════════
End-of-list.
</pre>
 
===version 2===
This REXX version won't work if any of the words have an embedded blank (or possible a tab character) in them, as in:
<lang rexx>/*REXX pgm separates a string of comma─delimited words ──► array; echos.*/
sss='Hello,How,Are,You,Today' /*words separated by commas (,). */
say 'input string =' sss /*display the original string. */
say; say 'Words in the string:' /*Display a header for the list. */
 
Hello,Betty Sue,How,Are,You,Today
do until sss=='' /*keep going until SSS is empty. */
<syntaxhighlight lang="rexx">/*REXX program to separate a string of comma-delimited words and echo */
parse var sss x ',' sss /*parse words delineated by comma*/
sss='Hello,How,Are,You,Today'
say x'.' /*show a word appended with a '.'*/
say 'input string='sss
end /*until*/
say ''
say 'Words in the string:'
ss =translate(sss,' ',',')
dot='.'
Do i=1 To words(ss)
If i=words(ss) Then dot=''
say word(ss,i)dot
End
say 'End-of-list.'</syntaxhighlight>
'''output''' is similar to REXX version 1.
 
=={{header|Ring}}==
say 'End-of-list.' /*Display a trailer for the list.*/</lang>
<syntaxhighlight lang="ring">
'''output''' is identical to Version 1.
see substr("Hello,How,Are,You,Today", ",", ".")
<br><br>
</syntaxhighlight>
 
===version 3={{header|RPL}}==
The program below fully complies with the task requirements, e.g. the input string is converted to a list of words, then the list is converted to a string.
<lang rexx>/*REXX program to separate a string of comma-delimited words and echo */
{{works with|Halcyon Calc|4.2.8}}
sss='Hello,How,Are,You,Today'
{| class="wikitable"
say 'input string='sss
! RPL code
say ''
! Comment
say 'Words in the string:'
|-
ss =translate(sss,' ',',')
|
Do i=1 To words(ss)
say word(ss,i)'.'
"}" + "{" SWAP + STR→
End
1 OVER SIZE '''FOR''' j
say 'End-of-list.'</lang>
DUP j GET →STR 2 OVER SIZE 1 - SUB j SWAP PUT
'''output''' is identical to Version 1.
'''NEXT'''
"" 1 3 PICK SIZE '''FOR''' j
OVER j GET +
'''IF''' OVER SIZE j ≠ '''THEN''' "." + '''END'''
'''NEXT''' SWAP DROP
≫ '<span style="color:blue">'''TOKNZ'''</span>' STO
|
<span style="color:blue">'''TOKNZ'''</span> ''<span style="color:grey">( "word,word" → "word.word" )</span> ''
convert string into list (words being between quotes)
loop for each list item
convert it to a string, remove quotes at beginning and end
loop for each list item
add item to output string
if not last item, append "."
clean stack
return output string
|}
 
"Hello,How,Are,You,Today" <span style="color:blue">'''TOKNZ'''</span>
</pre>
'''Output:'''
<span style="color:grey"> 1:</span> "Hello.How.Are.You.Today"
If direct string-to-string conversion is allowed, then this one-liner for HP-48+ will do the job:
≪ 1 OVER SIZE '''FOR''' j '''IF''' DUP j DUP SUB "," == '''THEN''' j "." REPL '''END NEXT''' ≫ '<span style="color:blue">'''TOKNZ'''</span>' STO
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">puts "Hello,How,Are,You,Today".split(',').join('.')</langsyntaxhighlight>
 
=={{header|Run BASICRust}}==
<syntaxhighlight lang="rust">fn main() {
<lang runbasic>text$ = "Hello,How,Are,You,Today"
let s = "Hello,How,Are,You,Today";
FOR i = 1 to 5
let tokens: Vec<&str> = s.split(",").collect();
textArray$(i) = word$(text$,i,",")
println!("{}", tokens.join("."));
print textArray$(i);" ";
}</syntaxhighlight>
NEXT</lang>
 
=={{header|S-lang}}==
<syntaxhighlight lang="s-lang">variable a = strchop("Hello,How,Are,You,Today", ',', 0);
print(strjoin(a, "."));</syntaxhighlight>
 
{{out}}
<pre>"Hello.How.Are.You.Today"</pre>
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">println("Hello,How,Are,You,Today" split "," mkString ".")</langsyntaxhighlight>
 
=={{header|Scheme}}==
{{works with|Guile}}
<langsyntaxhighlight lang="scheme">(use-modules (ice-9 regex))
(define s "Hello,How,Are,You,Today")
(define words (map match:substring (list-matches "[^,]+" s)))
Line 1,487 ⟶ 3,546:
(display (list-ref words n))
(if (< n (- (length words) 1))
(display ".")))</langsyntaxhighlight>
 
(with SRFI 13)
<langsyntaxhighlight lang="scheme">(define s "Hello,How,Are,You,Today")
(define words (string-tokenize s (char-set-complement (char-set #\,))))
(define t (string-join words "."))</langsyntaxhighlight>
 
{{works with|Gauche Scheme}}
<syntaxhighlight lang="scheme">(print
(string-join
(string-split "Hello,How,Are,You,Today" #\,)
".")) </syntaxhighlight>
{{output}}
<pre>
Hello.How.Are.You.Today
</pre>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">var array string: tokens is 0 times "";
 
tokens := split("Hello,How,Are,You,Today", ",");</langsyntaxhighlight>
 
=={{header|Self}}==
<syntaxhighlight lang="self">| s = 'Hello,How,Are,You,Today' |
((s splitOn: ',') joinUsing: '.') printLine.
</syntaxhighlight>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">'Hello,How,Are,You,Today'.split(',').join('.').say;</syntaxhighlight>
=={{header|Simula}}==
<syntaxhighlight lang="simula">BEGIN
 
CLASS TEXTARRAY(N); INTEGER N;
BEGIN
TEXT ARRAY ARR(1:N);
END TEXTARRAY;
 
REF(TEXTARRAY) PROCEDURE SPLIT(T,DELIM); TEXT T; CHARACTER DELIM;
BEGIN
INTEGER N, I, LPOS;
REF(TEXTARRAY) A;
 
N := 1;
T.SETPOS(1);
WHILE T.MORE DO
IF T.GETCHAR = DELIM THEN
N := N+1;
A :- NEW TEXTARRAY(N);
 
I := 0;
LPOS := 1;
T.SETPOS(LPOS);
WHILE T.MORE DO
IF T.GETCHAR = DELIM THEN
BEGIN
I := I+1;
A.ARR(I) :- T.SUB(LPOS,T.POS-LPOS-1);
LPOS := T.POS;
END;
I := I+1;
A.ARR(I) :- T.SUB(LPOS,T.LENGTH-LPOS+1);
SPLIT :- A;
END SPLIT;
 
BEGIN
TEXT S;
REF(TEXTARRAY) TA;
INTEGER I;
 
S :- "HELLO,HOW,ARE,YOU,TODAY";
TA :- SPLIT(S,',');
FOR I := 1 STEP 1 UNTIL TA.N DO
BEGIN
OUTTEXT(TA.ARR(I));
OUTCHAR('.');
END;
OUTIMAGE;
END;
 
END.
</syntaxhighlight>
{{out}}
<pre>HELLO.HOW.ARE.YOU.TODAY.</pre>
 
=={{header|Slate}}==
<langsyntaxhighlight lang="slate">('Hello,How,Are,You,Today' splitWith: $,) join &separator: '.'.</langsyntaxhighlight>
 
=={{header|Slope}}==
<syntaxhighlight lang="slope">(display
(list->string
(string->list
"Hello,How,Are,You,Today"
",")
"."))</syntaxhighlight>
{{out}}
<pre>Hello.How.Are.You.Today</pre>
 
=={{header|Smalltalk}}==
<langsyntaxhighlight lang="smalltalk">|array |
array := 'Hello,How,Are,You,Today' subStrings: $,.
array fold: [:concatenation :string | concatenation, '.', string ]</langsyntaxhighlight>
 
Some implementations also have a ''join:'' convenience method that allows the following shorter solution:
 
<langsyntaxhighlight lang="smalltalk">('Hello,How,Are,You,Today' subStrings: $,) join: '.'</langsyntaxhighlight>
 
The solution displaying a trailing period would be:
 
<langsyntaxhighlight lang="smalltalk">|array |
array := 'Hello,How,Are,You,Today' subStrings: $,.
array inject: '' into: [:concatenation :string | concatenation, string, '.' ]</langsyntaxhighlight>
 
=={{header|SNOBOL4}}==
Line 1,521 ⟶ 3,662:
For this task, it's convenient to define Perl-style split( ) and join( ) functions.
 
<langsyntaxhighlight SNOBOL4lang="snobol4"> define('split(chs,str)i,j,t,w2') :(split_end)
split t = table()
sp1 str pos(0) (break(chs) | rem) $ t<i = i + 1>
Line 1,537 ⟶ 3,678:
* # Test and display
output = join('.',split(',','Hello,How,Are,You,Today'))
end</langsyntaxhighlight>
 
{{out}}
Output:
<pre>
Hello.How.Are.You.Today
</pre>
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="sml">val splitter = String.tokens (fn c => c = #",");
val main = (String.concatWith ".") o splitter;</langsyntaxhighlight>
 
Test:
 
<langsyntaxhighlight lang="sml">- main "Hello,How,Are,You,Today"
val it = "Hello.How.Are.You.Today" : string</langsyntaxhighlight>
 
=={{header|Swift}}==
 
{{works with|Swift|3.x}}
<syntaxhighlight lang="swift">let text = "Hello,How,Are,You,Today"
let tokens = text.components(separatedBy: ",") // for single or multi-character separator
print(tokens)
let result = tokens.joined(separator: ".")
print(result)</syntaxhighlight>
 
{{works with|Swift|2.x}}
<syntaxhighlight lang="swift">let text = "Hello,How,Are,You,Today"
let tokens = text.characters.split(",").map{String($0)} // for single-character separator
print(tokens)
let result = tokens.joinWithSeparator(".")
print(result)</syntaxhighlight>
 
{{works with|Swift|1.x}}
<syntaxhighlight lang="swift">let text = "Hello,How,Are,You,Today"
let tokens = split(text, { $0 == "," }) // for single-character separator
println(tokens)
let result = ".".join(tokens)
println(result)</syntaxhighlight>
 
For multi-character separators:<syntaxhighlight lang="swift">import Foundation
 
let text = "Hello,How,Are,You,Today"
let tokens = text.componentsSeparatedByString(",")
print(tokens)</syntaxhighlight>
 
=={{header|Tcl}}==
Generating a list form a string by splitting on a comma:
<langsyntaxhighlight lang="tcl">split $string ","</langsyntaxhighlight>
 
Joining the elements of a list by a period:
<langsyntaxhighlight lang="tcl">join $list "."</langsyntaxhighlight>
 
Thus the whole thing would look like this:
<langsyntaxhighlight lang="tcl">puts [join [split "Hello,How,Are,You,Today" ","] "."]</langsyntaxhighlight>
 
If you'd like to retain the list in a variable with the name "words", it would only be marginally more complex:
<langsyntaxhighlight lang="tcl">puts [join [set words [split "Hello,How,Are,You,Today" ","]] "."]</langsyntaxhighlight>
 
(In general, the <tt>regexp</tt> command is also used in Tcl for tokenization of strings, but this example does not need that level of complexity.)
Line 1,569 ⟶ 3,741:
<code>tr</code> knows nothing about arrays, so this solution only changes each comma to a period.
 
<langsyntaxhighlight lang="bash">echo 'Hello,How,Are,You,Today' | tr ',' '.'</langsyntaxhighlight>
 
=={{header|Transd}}==
<syntaxhighlight lang="Scheme">#lang transd
 
MainModule: {
_start: (lambda locals: s "Hello,How,Are,You,Today"
(textout (join (split s ",") "."))
)
}</syntaxhighlight>
{{out}}
<pre>
Hello.How.Are.You.Today
</pre>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
SET string="Hello,How,Are,You,Today"
SET string=SPLIT (string,":,:")
SET string=JOIN (string,".")
</syntaxhighlight>
</lang>
 
=={{header|TXR}}==
Line 1,584 ⟶ 3,769:
sequences of non-commas.
 
<langsyntaxhighlight lang="txr">@(next :list "Hello,How,Are,You,Today")
@(coll)@{token /[^,]+/}@(end)
@(output)
@(rep)@token.@(last)@token@(end)
@(end)</langsyntaxhighlight>
 
Different approach. Collect tokens, each of
Line 1,594 ⟶ 3,779:
before a comma, or else extends to the end of the line.
 
<langsyntaxhighlight lang="txr">@(next :list "Hello,How,Are,You,Today")
@(coll)@(maybe)@token,@(or)@token@(end)@(end)
@(output)
@(rep)@token.@(last)@token@(end)
@(end)</langsyntaxhighlight>
 
Using TXR Lisp:
 
<syntaxhighlight lang ="bash">txr>@(bind result-p @'(cat-str (split-str "Hello,How,Are,You,Today" ",") "."))</lang>'
Hello.How.Are.You.Today</syntaxhighlight>
 
$ txr tok.txr
result="Hello.How.Are.You.Today"
 
=={{header|UNIX Shell}}==
{{works with|Bourne Shell}}
<langsyntaxhighlight lang="bash">string='Hello,How,Are,You,Today'
 
(IFS=,
printf '%s.' $string
echo)</langsyntaxhighlight>
 
----
{{works with|Bourne Again SHell}}
{{works with|Public Domain Korn SHell|5.2.14}}
<langsyntaxhighlight lang="bash">#! /bin/bash
stripchar-l ()
#removes the specified character from the left side of the string
Line 1,675 ⟶ 3,858:
join "$( split "$list" "$input_delimiter" )" \
"$contains_a_space" "$output_delimiter";
}</langsyntaxhighlight>
 
''Example''
 
<langsyntaxhighlight lang="bash"> strtokenize "Hello,How,Are,You,Today" "," "."
Hello.How.Are.You.Today </langsyntaxhighlight>
 
----
{{works with|Almquist Shell}}
{{works with|bash}}
{{works with|pdksh}}
{{works with|ksh93}}
{{works with|zsh}}
<syntaxhighlight lang="sh">
string1="Hello,How,Are,You,Today"
elements_quantity=$(echo $string1|tr "," "\n"|wc -l)
 
present_element=1
while [ $present_element -le $elements_quantity ];do
echo $string1|cut -d "," -f $present_element|tr -d "\n"
if [ $present_element -lt $elements_quantity ];then echo -n ".";fi
present_element=$(expr $present_element + 1)
done
echo
 
# or to cheat
echo "Hello,How,Are,You,Today"|tr "," "."</syntaxhighlight>
 
=={{header|UnixPipes}}==
{{works with|Bourne Shell}}
<langsyntaxhighlight lang="bash">token() {
(IFS=, read -r A B; echo "$A".; test -n "$B" && (echo "$B" | token))
}
 
echo "Hello,How,Are,You" | token</langsyntaxhighlight>
 
=={{header|Ursa}}==
<syntaxhighlight lang="ursa">decl string text
set text "Hello,How,Are,You,Today"
decl string<> tokens
set tokens (split text ",")
for (decl int i) (< i (size tokens)) (inc i)
out tokens<i> "." console
end for
out endl console</syntaxhighlight>
 
=={{header|Ursala}}==
Line 1,696 ⟶ 3,910:
second order function parameterized by the delimiter. Character
literals are preceded by a backquote.
<langsyntaxhighlight Ursalalang="ursala">#import std
 
token_list = sep`, 'Hello,How,Are,You,Today'
Line 1,702 ⟶ 3,916:
#cast %s
 
main = mat`. token_list</langsyntaxhighlight>
{{out}}
Output:
<pre>
'Hello.How.Are.You.Today'
</pre>
 
=={{header|Vala}}==
<syntaxhighlight lang="vala">void main() {
<lang vala>// declare test string
string s = "Hello,How,Are,You,Today";
print(@"$(string.joinv(".", s.split(",")))");
// create array of strings, could use var words instead if desired
}</syntaxhighlight>
string[] words = s.split(",");
{{out}}
// create string by joining array of strings with .
<pre>Hello.How.Are.You.Today</pre>
string joined = string.joinv(".", words);</lang>
 
=={{header|VBScriptVBA}}==
<syntaxhighlight lang="vb">Sub Main()
====One liner====
Dim temp() As String
<lang vb>WScript.Echo Join(Split("Hello,How,Are,You,Today", ","), ".")</lang>
temp = Tokenize("Hello,How,Are,You,Today", ",")
Display temp, Space(5)
End Sub
 
Private Function Tokenize(strS As String, sep As String) As String()
In fact, the Visual Basic solution (below) could have done the same, as Join() is available.
Tokenize = Split(strS, sep)
End Function
 
Private Sub Display(arr() As String, sep As String)
Debug.Print Join(arr, sep)
End Sub</syntaxhighlight>
{{Out}}
<pre>Hello How Are You Today</pre>
 
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
s = "Hello,How,Are,You,Today"
WScript.StdOut.Write Join(Split(s,","),".")
</syntaxhighlight>
{{Out}}
<pre>Hello.How.Are.You.Today</pre>
 
=={{header|Vedit macro language}}==
Line 1,726 ⟶ 3,961:
The contents of each text register is then displayed to user, separated by a period.
 
<langsyntaxhighlight lang="vedit">Buf_Switch(Buf_Free)
Ins_Text("Hello,How,Are,You,Today")
 
Line 1,745 ⟶ 3,980:
}
 
Buf_Quit(OK)</langsyntaxhighlight>
 
=={{header|VisualV Basic(Vlang)}}==
<syntaxhighlight lang="go">// Tokenize a string, in V (Vlang)
{{trans|PowerBASIC}}
// Tectonics: v run tokenize-a-string.v
module main
 
// starts here
Unlike PowerBASIC, there is no need to know beforehand how many tokens are in the string -- <code>Split</code> automagically builds the array for you.
pub fn main() {
println("Hello,How,Are,You,Today".split(',').join('.'))
}</syntaxhighlight>
{{out}}
<pre>prompt$ v run rosetta/tokenize-a-string.v
Hello.How.Are.You.Today</pre>
 
=={{header|WinBatch}}==
<lang vb>Sub Main()
Dim parseMe As String, parsed As Variant
parseMe = "Hello,How,Are,You,Today"
 
<syntaxhighlight lang="winbatch">text = 'Hello,How,Are,You,Today'
parsed = Split(parseMe, ",")
result = ''
BoxOpen('WinBatch Tokenizing Example', '')
for ix = 1 to itemcount(text,',')
result = result : itemextract(ix, text, ',') : '.'
BoxText(result)
next
display(10, 'End of Program', 'Dialog and program will close momentarily.')
BoxShut()</syntaxhighlight>
 
{{out}}
Dim L0 As Long, outP As String
Hello.How.Are.You.Today.
outP = parsed(0)
For L0 = 1 To UBound(parsed)
outP = outP & "." & parsed(L0)
Next
 
=={{header|Wortel}}==
MsgBox outP
<syntaxhighlight lang="wortel">@join "." @split "," "Hello,How,Are,You,Today"</syntaxhighlight>
End Sub</lang>
Returns
<pre>"Hello.How.Are.You.Today"</pre>
 
=={{header|Wren}}==
<syntaxhighlight lang="wren">var s = "Hello,How,Are,You,Today"
var t = s.split(",").join(".") + "."
System.print(t)</syntaxhighlight>
 
{{out}}
<pre>
Hello.How.Are.You.Today.
</pre>
 
=={{header|XPath 2.0}}==
<syntaxhighlight lang="xpath">string-join(tokenize("Hello,How,Are,You,Today", ","), ".")</syntaxhighlight>
 
{{out}}
Hello.How.Are.You.Today
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">string 0;
include c:\cxpl\codes;
int I, J, K, Char;
Line 1,787 ⟶ 4,051:
for K:= 4 downto 0 do [Text(0, addr Array(K,0)); ChOut(0, ^.)];
CrLf(0);
]</langsyntaxhighlight>
 
The 'addr' operator is used to fetch the 32-bit address of Array rather
Line 1,796 ⟶ 4,060:
Today.You.Are.How.Hello.
</pre>
 
=={{header|Yabasic}}==
<syntaxhighlight lang="yabasic">dim s$(1)
 
n = token("Hello. How are you today?", s$(), ".? ")
 
for i = 1 to n
print s$(i);
if i < n print ".";
next
print</syntaxhighlight>
 
=={{header|Zig}}==
<syntaxhighlight lang="zig">const std = @import("std");
pub fn main() void {
const string = "Hello,How,Are,You,Today";
var tokens = std.mem.split(u8, string, ",");
std.debug.print("{s}", .{tokens.next().?});
while (tokens.next()) |token| {
std.debug.print(".{s}", .{token});
}
}</syntaxhighlight>
=={{header|zkl}}==
<syntaxhighlight lang="zkl">"Hello,How,Are,You,Today".split(",").concat(".").println();
Hello.How.Are.You.Today</syntaxhighlight>
 
=={{header|Zoea}}==
<syntaxhighlight lang="zoea">
program: tokenize_a_string
input: "Hello,How,Are,You,Today"
output: "Hello.How.Are.You.Today"
</syntaxhighlight>
 
=={{header|Zoea Visual}}==
[http://zoea.co.uk/examples/zv-rc/Tokenize_string.png Tokenize a string]
 
=={{header|Zsh}}==
<langsyntaxhighlight lang="zsh">str='Hello,How,Are,You,Today'
tokens=(${(s:,:)str})
print ${(j:.:)tokens}</langsyntaxhighlight>
 
Or, using SH_SPLIT_WORD:
 
<langsyntaxhighlight lang="zsh">str='Hello,How,Are,You,Today'
IFS=, echo ${(j:.:)${=str}}</langsyntaxhighlight>
 
{{omit from|PARI/GP|No real capacity for string manipulation}}
9,482

edits