Tokenize a string: Difference between revisions

Content added Content deleted
m (→‎{{header|Picat}}: code tags)
m (syntax highlighting fixup automation)
Line 15: Line 15:
{{trans|Python}}
{{trans|Python}}


<lang 11l>V text = ‘Hello,How,Are,You,Today’
<syntaxhighlight lang="11l">V text = ‘Hello,How,Are,You,Today’
V tokens = text.split(‘,’)
V tokens = text.split(‘,’)
print(tokens.join(‘.’))</lang>
print(tokens.join(‘.’))</syntaxhighlight>


{{out}}
{{out}}
Line 25: Line 25:


=={{header|360 Assembly}}==
=={{header|360 Assembly}}==
<lang 360asm>* Tokenize a string - 08/06/2018
<syntaxhighlight lang="360asm">* Tokenize a string - 08/06/2018
TOKSTR CSECT
TOKSTR CSECT
USING TOKSTR,R13 base register
USING TOKSTR,R13 base register
Line 107: Line 107:
PG DC CL80' ' buffer
PG DC CL80' ' buffer
YREGS
YREGS
END TOKSTR</lang>
END TOKSTR</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 114: Line 114:


=={{header|8080 Assembly}}==
=={{header|8080 Assembly}}==
<lang 8080asm>puts: equ 9
<syntaxhighlight lang="8080asm">puts: equ 9
org 100h
org 100h
jmp demo
jmp demo
Line 161: Line 161:
period: db '. $'
period: db '. $'
hello: db 'Hello,How,Are,You,Today$'
hello: db 'Hello,How,Are,You,Today$'
parts: equ $</lang>
parts: equ $</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello. How. Are. You. Today.</pre>
<pre>Hello. How. Are. You. Today.</pre>
=={{header|8086 Assembly}}==
=={{header|8086 Assembly}}==
<lang asm> cpu 8086
<syntaxhighlight lang="asm"> cpu 8086
org 100h
org 100h
section .text
section .text
Line 203: Line 203:
hello: db 'Hello,How,Are,You,Today$'
hello: db 'Hello,How,Are,You,Today$'
section .bss
section .bss
parts: resw 10</lang>
parts: resw 10</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello. How. Are. You. Today. </pre>
<pre>Hello. How. Are. You. Today. </pre>
Line 209: Line 209:
=={{header|AArch64 Assembly}}==
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
<lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program strTokenize64.s */
/* program strTokenize64.s */
Line 349: Line 349:
/* for this file see task include a file in language AArch64 assembly */
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>
{{Output}}
{{Output}}
<pre>
<pre>
Line 361: Line 361:


=={{header|ACL2}}==
=={{header|ACL2}}==
<lang lisp>(defun split-at (xs delim)
<syntaxhighlight lang="lisp">(defun split-at (xs delim)
(if (or (endp xs) (eql (first xs) delim))
(if (or (endp xs) (eql (first xs) delim))
(mv nil (rest xs))
(mv nil (rest xs))
Line 389: Line 389:
(progn$ (cw (first strs))
(progn$ (cw (first strs))
(cw (coerce (list delim) 'string))
(cw (coerce (list delim) 'string))
(print-with (rest strs) delim))))</lang>
(print-with (rest strs) delim))))</syntaxhighlight>


{{out}}
{{out}}
Line 398: Line 398:
The user must type in the monitor the following command after compilation and before running the program!<pre>SET EndProg=*</pre>
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}}
{{libheader|Action! Tool Kit}}
<lang Action!>CARD EndProg ;required for ALLOCATE.ACT
<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!
INCLUDE "D2:ALLOCATE.ACT" ;from the Action! Tool Kit. You must type 'SET EndProg=*' from the monitor after compiling, but before running this program!
Line 491: Line 491:
Clear(items,@count)
Clear(items,@count)
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Tokenize_a_string.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Tokenize_a_string.png Screenshot from Atari 8-bit computer]
Line 506: Line 506:


=={{header|ActionScript}}==
=={{header|ActionScript}}==
<lang actionscript>var hello:String = "Hello,How,Are,You,Today";
<syntaxhighlight lang="actionscript">var hello:String = "Hello,How,Are,You,Today";
var tokens:Array = hello.split(",");
var tokens:Array = hello.split(",");
trace(tokens.join("."));
trace(tokens.join("."));


// Or as a one-liner
// Or as a one-liner
trace("Hello,How,Are,You,Today".split(",").join("."));</lang>
trace("Hello,How,Are,You,Today".split(",").join("."));</syntaxhighlight>


=={{header|Ada}}==
=={{header|Ada}}==
<lang ada>with Ada.Text_IO, Ada.Containers.Indefinite_Vectors, Ada.Strings.Fixed, Ada.Strings.Maps;
<syntaxhighlight lang="ada">with Ada.Text_IO, Ada.Containers.Indefinite_Vectors, Ada.Strings.Fixed, Ada.Strings.Maps;
use Ada.Text_IO, Ada.Containers, Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps;
use Ada.Text_IO, Ada.Containers, Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps;


Line 534: Line 534:
Put (S & ".");
Put (S & ".");
end loop;
end loop;
end Tokenize;</lang>
end Tokenize;</syntaxhighlight>


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
<lang algol68>main:(
<syntaxhighlight lang="algol68">main:(


OP +:= = (REF FLEX[]STRING in out, STRING item)VOID:(
OP +:= = (REF FLEX[]STRING in out, STRING item)VOID:(
Line 585: Line 585:
printf(($g"."$, string split(beetles, ", "),$l$));
printf(($g"."$, string split(beetles, ", "),$l$));
printf(($g"."$, char split(beetles, ", "),$l$))
printf(($g"."$, char split(beetles, ", "),$l$))
)</lang>
)</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 603: Line 603:
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.
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">
<lang Hopper>
#include <hopper.h>
#include <hopper.h>


Line 668: Line 668:
back
back


</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>Output:
<pre>Output:
Line 688: Line 688:


=={{header|APL}}==
=={{header|APL}}==
<lang APL> '.',⍨¨ ','(≠⊆⊢)'abc,123,X' ⍝ [1] Do the split: ','(≠⊆⊢)'abc,123,X'; [2] append the periods: '.',⍨¨
<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.
abc. 123. X. ⍝ 3 strings (char vectors), each with a period at the end.
</syntaxhighlight>
</lang>


=={{header|AppleScript}}==
=={{header|AppleScript}}==


<lang applescript>on run
<syntaxhighlight lang="applescript">on run
intercalate(".", splitOn(",", "Hello,How,Are,You,Today"))
intercalate(".", splitOn(",", "Hello,How,Are,You,Today"))
end run
end run
Line 713: Line 713:
set my text item delimiters to dlm
set my text item delimiters to dlm
return strJoined
return strJoined
end intercalate</lang>
end intercalate</syntaxhighlight>
{{Out}}
{{Out}}
<pre>Hello.How.Are.You.Today</pre>
<pre>Hello.How.Are.You.Today</pre>
Line 719: Line 719:
Or,
Or,


<lang AppleScript>set my text item delimiters to ","
<syntaxhighlight lang="applescript">set my text item delimiters to ","
set tokens to the text items of "Hello,How,Are,You,Today"
set tokens to the text items of "Hello,How,Are,You,Today"


set my text item delimiters to "."
set my text item delimiters to "."
log tokens as text</lang>
log tokens as text</syntaxhighlight>


{{Out}}
{{Out}}
Line 731: Line 731:
=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>


/* ARM assembly Raspberry PI */
/* ARM assembly Raspberry PI */
Line 895: Line 895:
bx lr
bx lr
</syntaxhighlight>
</lang>


=={{header|Arturo}}==
=={{header|Arturo}}==
<lang rebol>str: "Hello,How,Are,You,Today"
<syntaxhighlight lang="rebol">str: "Hello,How,Are,You,Today"


print join.with:"." split.by:"," str</lang>
print join.with:"." split.by:"," str</syntaxhighlight>


{{out}}
{{out}}
Line 907: Line 907:


=={{header|Astro}}==
=={{header|Astro}}==
<lang python>let text = 'Hello,How,Are,You,Today'
<syntaxhighlight lang="python">let text = 'Hello,How,Are,You,Today'
let tokens = text.split(||,||)
let tokens = text.split(||,||)
print tokens.join(with: '.')</lang>
print tokens.join(with: '.')</syntaxhighlight>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
<lang AutoHotkey>string := "Hello,How,Are,You,Today"
<syntaxhighlight lang="autohotkey">string := "Hello,How,Are,You,Today"
stringsplit, string, string, `,
stringsplit, string, string, `,
loop, % string0
loop, % string0
{
{
msgbox % string%A_Index%
msgbox % string%A_Index%
}</lang>
}</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==


<lang awk>BEGIN {
<syntaxhighlight lang="awk">BEGIN {
s = "Hello,How,Are,You,Today"
s = "Hello,How,Are,You,Today"
split(s, arr, ",")
split(s, arr, ",")
Line 928: Line 928:
}
}
print
print
}</lang>
}</syntaxhighlight>


A more ''idiomatic'' way for AWK is
A more ''idiomatic'' way for AWK is


<lang awk>BEGIN { FS = "," }
<syntaxhighlight lang="awk">BEGIN { FS = "," }
{
{
for(i=1; i <= NF; i++) printf $i ".";
for(i=1; i <= NF; i++) printf $i ".";
print ""
print ""
}</lang>
}</syntaxhighlight>


which "tokenize" each line of input and this is achieved by using "," as field separator
which "tokenize" each line of input and this is achieved by using "," as field separator
Line 942: Line 942:
=={{header|BASIC}}==
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
==={{header|Applesoft BASIC}}===
<lang ApplesoftBasic>100 T$ = "HELLO,HOW,ARE,YOU,TODAY"
<syntaxhighlight lang="applesoftbasic">100 T$ = "HELLO,HOW,ARE,YOU,TODAY"
110 GOSUB 200"TOKENIZE
110 GOSUB 200"TOKENIZE
120 FOR I = 1 TO N
120 FOR I = 1 TO N
Line 961: Line 961:
290 A$(N) = A$(N) + C$
290 A$(N) = A$(N) + C$
300 NEXT TI
300 NEXT TI
310 RETURN</lang>
310 RETURN</syntaxhighlight>


==={{header|BaCon}}===
==={{header|BaCon}}===
BaCon includes extensive support for ''delimited strings''.
BaCon includes extensive support for ''delimited strings''.
<lang bacon>OPTION BASE 1
<syntaxhighlight lang="bacon">OPTION BASE 1


string$ = "Hello,How,Are,You,Today"
string$ = "Hello,How,Are,You,Today"
Line 976: Line 976:


' Or simply replace the delimiter
' Or simply replace the delimiter
PRINT DELIM$(string$, ",", ".")</lang>
PRINT DELIM$(string$, ",", ".")</syntaxhighlight>


{{out}}
{{out}}
Line 984: Line 984:


==={{header|BASIC256}}===
==={{header|BASIC256}}===
<lang BASIC256>instring$ = "Hello,How,Are,You,Today"
<syntaxhighlight lang="basic256">instring$ = "Hello,How,Are,You,Today"


tokens$ = explode(instring$,",")
tokens$ = explode(instring$,",")
Line 990: Line 990:
print tokens$[i]; ".";
print tokens$[i]; ".";
next i
next i
end</lang>
end</syntaxhighlight>




==={{header|BBC BASIC}}===
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
<lang bbcbasic> INSTALL @lib$+"STRINGLIB"
<syntaxhighlight lang="bbcbasic"> INSTALL @lib$+"STRINGLIB"
text$ = "Hello,How,Are,You,Today"
text$ = "Hello,How,Are,You,Today"
Line 1,002: Line 1,002:
PRINT array$(i%) "." ;
PRINT array$(i%) "." ;
NEXT
NEXT
PRINT</lang>
PRINT</syntaxhighlight>


==={{header|Commodore BASIC}}===
==={{header|Commodore BASIC}}===
Based on the AppleSoft BASIC version.
Based on the AppleSoft BASIC version.
<lang commodorebasic>
<syntaxhighlight lang="commodorebasic">
10 REM TOKENIZE A STRING ... ROSETTACODE.ORG
10 REM TOKENIZE A STRING ... ROSETTACODE.ORG
20 T$ = "HELLO,HOW,ARE,YOU,TODAY"
20 T$ = "HELLO,HOW,ARE,YOU,TODAY"
Line 1,024: Line 1,024:
270 NEXT L
270 NEXT L
280 RETURN
280 RETURN
</syntaxhighlight>
</lang>
==={{header|FreeBASIC}}===
==={{header|FreeBASIC}}===
<lang freebasic>sub tokenize( instring as string, tokens() as string, sep as string )
<syntaxhighlight lang="freebasic">sub tokenize( instring as string, tokens() as string, sep as string )
redim tokens(0 to 0) as string
redim tokens(0 to 0) as string
dim as string*1 ch
dim as string*1 ch
Line 1,047: Line 1,047:
for i as uinteger = 0 to ubound(tokens)
for i as uinteger = 0 to ubound(tokens)
print tokens(i);".";
print tokens(i);".";
next i</lang>
next i</syntaxhighlight>


==={{header|Liberty BASIC}}===
==={{header|Liberty BASIC}}===
<lang lb>'Note that Liberty Basic's array usage can reach element #10 before having to DIM the array
<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
For i = 0 To 4
array$(i) = Word$("Hello,How,Are,You,Today", (i + 1), ",")
array$(i) = Word$("Hello,How,Are,You,Today", (i + 1), ",")
Line 1,056: Line 1,056:
Next i
Next i


Print Left$(array$, (Len(array$) - 1))</lang>
Print Left$(array$, (Len(array$) - 1))</syntaxhighlight>


==={{header|PowerBASIC}}===
==={{header|PowerBASIC}}===
Line 1,062: Line 1,062:
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.)
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
<syntaxhighlight lang="powerbasic">FUNCTION PBMAIN () AS LONG
DIM parseMe AS STRING
DIM parseMe AS STRING
parseMe = "Hello,How,Are,You,Today"
parseMe = "Hello,How,Are,You,Today"
Line 1,076: Line 1,076:


MSGBOX outP
MSGBOX outP
END FUNCTION</lang>
END FUNCTION</syntaxhighlight>


==={{header|PureBasic}}===
==={{header|PureBasic}}===


'''As described
'''As described
<lang PureBasic>NewList MyStrings.s()
<syntaxhighlight lang="purebasic">NewList MyStrings.s()


For i=1 To 5
For i=1 To 5
Line 1,090: Line 1,090:
ForEach MyStrings()
ForEach MyStrings()
Print(MyStrings()+".")
Print(MyStrings()+".")
Next</lang>
Next</syntaxhighlight>


'''Still, easier would be
'''Still, easier would be
<lang PureBasic>Print(ReplaceString("Hello,How,Are,You,Today",",","."))</lang>
<syntaxhighlight lang="purebasic">Print(ReplaceString("Hello,How,Are,You,Today",",","."))</syntaxhighlight>


==={{header|QBasic}}===
==={{header|QBasic}}===
<lang qbasic>DIM parseMe AS STRING
<syntaxhighlight lang="qbasic">DIM parseMe AS STRING
parseMe = "Hello,How,Are,You,Today"
parseMe = "Hello,How,Are,You,Today"


Line 1,140: Line 1,140:
PRINT "."; parsed(L0);
PRINT "."; parsed(L0);
NEXT
NEXT
END IF</lang>
END IF</syntaxhighlight>


==={{header|Run BASIC}}===
==={{header|Run BASIC}}===
<lang runbasic>text$ = "Hello,How,Are,You,Today"
<syntaxhighlight lang="runbasic">text$ = "Hello,How,Are,You,Today"
FOR i = 1 to 5
FOR i = 1 to 5
textArray$(i) = word$(text$,i,",")
textArray$(i) = word$(text$,i,",")
print textArray$(i);" ";
print textArray$(i);" ";
NEXT</lang>
NEXT</syntaxhighlight>


==={{header|VBScript}}===
==={{header|VBScript}}===
====One liner====
====One liner====
<lang vb>WScript.Echo Join(Split("Hello,How,Are,You,Today", ","), ".")</lang>
<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.
In fact, the Visual Basic solution (below) could have done the same, as Join() is available.
Line 1,160: Line 1,160:
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.
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.


<lang vb>Sub Main()
<syntaxhighlight lang="vb">Sub Main()
Dim parseMe As String, parsed As Variant
Dim parseMe As String, parsed As Variant
parseMe = "Hello,How,Are,You,Today"
parseMe = "Hello,How,Are,You,Today"
Line 1,173: Line 1,173:


MsgBox outP
MsgBox outP
End Sub</lang>
End Sub</syntaxhighlight>


=={{header|Batch File}}==
=={{header|Batch File}}==
<lang dos>@echo off
<syntaxhighlight lang="dos">@echo off
setlocal enabledelayedexpansion
setlocal enabledelayedexpansion
call :tokenize %1 res
call :tokenize %1 res
Line 1,187: Line 1,187:
for %%i in (%str%) do set %2=!%2!.%%i
for %%i in (%str%) do set %2=!%2!.%%i
set %2=!%2:~1!
set %2=!%2:~1!
goto :eof</lang>
goto :eof</syntaxhighlight>


''Demo''
''Demo''
Line 1,195: Line 1,195:
=={{header|Bracmat}}==
=={{header|Bracmat}}==
Solution that employs string pattern matching to spot the commas
Solution that employs string pattern matching to spot the commas
<lang bracmat>( "Hello,How,Are,You,Today":?String
<syntaxhighlight lang="bracmat">( "Hello,How,Are,You,Today":?String
& :?ReverseList
& :?ReverseList
& whl
& whl
Line 1,207: Line 1,207:
)
)
& out$!List
& out$!List
)</lang>
)</syntaxhighlight>
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.
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.
<lang bracmat>( get$("Hello,How,Are,You,Today",MEM):?CommaseparatedList
<syntaxhighlight lang="bracmat">( get$("Hello,How,Are,You,Today",MEM):?CommaseparatedList
& :?ReverseList
& :?ReverseList
& whl
& whl
Line 1,221: Line 1,221:
)
)
& out$!List
& out$!List
)</lang>
)</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==
Line 1,230: Line 1,230:
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()''.
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()''.


<lang c>#include<string.h>
<syntaxhighlight lang="c">#include<string.h>
#include<stdio.h>
#include<stdio.h>
#include<stdlib.h>
#include<stdlib.h>
Line 1,251: Line 1,251:


return 0;
return 0;
}</lang>
}</syntaxhighlight>


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.
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.
<lang c>#include<stdio.h>
<syntaxhighlight lang="c">#include<stdio.h>


typedef void (*callbackfunc)(const char *);
typedef void (*callbackfunc)(const char *);
Line 1,279: Line 1,279:
tokenize(array, ',', doprint);
tokenize(array, ',', doprint);
return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>string str = "Hello,How,Are,You,Today";
<syntaxhighlight lang="csharp">string str = "Hello,How,Are,You,Today";
// or Regex.Split ( "Hello,How,Are,You,Today", "," );
// or Regex.Split ( "Hello,How,Are,You,Today", "," );
// (Regex is in System.Text.RegularExpressions namespace)
// (Regex is in System.Text.RegularExpressions namespace)
string[] strings = str.Split(',');
string[] strings = str.Split(',');
Console.WriteLine(String.Join(".", strings));
Console.WriteLine(String.Join(".", strings));
</syntaxhighlight>
</lang>


=={{header|C++}}==
=={{header|C++}}==
Line 1,294: Line 1,294:
std::getline() is typically used to tokenize strings on a single-character delimiter
std::getline() is typically used to tokenize strings on a single-character delimiter


<lang cpp>#include <string>
<syntaxhighlight lang="cpp">#include <string>
#include <sstream>
#include <sstream>
#include <vector>
#include <vector>
Line 1,309: Line 1,309:
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."));
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."));
std::cout << '\n';
std::cout << '\n';
}</lang>
}</syntaxhighlight>


{{works with|C++98}}
{{works with|C++98}}
C++ allows the user to redefine what is considered whitespace. If the delimiter is whitespace, tokenization becomes effortless.
C++ allows the user to redefine what is considered whitespace. If the delimiter is whitespace, tokenization becomes effortless.


<lang cpp>#include <string>
<syntaxhighlight lang="cpp">#include <string>
#include <locale>
#include <locale>
#include <sstream>
#include <sstream>
Line 1,338: Line 1,338:
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."));
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."));
std::cout << '\n';
std::cout << '\n';
}</lang>
}</syntaxhighlight>


{{works with|C++98}}
{{works with|C++98}}
Line 1,344: Line 1,344:
The boost library has multiple options for easy tokenization.
The boost library has multiple options for easy tokenization.


<lang cpp>#include <string>
<syntaxhighlight lang="cpp">#include <string>
#include <vector>
#include <vector>
#include <iterator>
#include <iterator>
Line 1,357: Line 1,357:
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."))
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."))
std::cout << '\n';
std::cout << '\n';
}</lang>
}</syntaxhighlight>


=={{header|Ceylon}}==
=={{header|Ceylon}}==
{{works with|Ceylon 1.2}}
{{works with|Ceylon 1.2}}
<lang ceylon>shared void tokenizeAString() {
<syntaxhighlight lang="ceylon">shared void tokenizeAString() {
value input = "Hello,How,Are,You,Today";
value input = "Hello,How,Are,You,Today";
value tokens = input.split(','.equals);
value tokens = input.split(','.equals);
print(".".join(tokens));
print(".".join(tokens));
}</lang>
}</syntaxhighlight>


=={{header|CFEngine}}==
=={{header|CFEngine}}==
<lang cfengine>bundle agent main
<syntaxhighlight lang="cfengine">bundle agent main
{
{
reports:
reports:
"${with}" with => join(".", splitstring("Hello,How,Are,You,Today", ",", 99));
"${with}" with => join(".", splitstring("Hello,How,Are,You,Today", ",", 99));
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>cf-agent -KIf ./tokenize-a-string.cf
<pre>cf-agent -KIf ./tokenize-a-string.cf
Line 1,382: Line 1,382:
=={{header|Clojure}}==
=={{header|Clojure}}==
Using native Clojure functions and Java Interop:
Using native Clojure functions and Java Interop:
<lang clojure>(apply str (interpose "." (.split #"," "Hello,How,Are,You,Today")))</lang>
<syntaxhighlight lang="clojure">(apply str (interpose "." (.split #"," "Hello,How,Are,You,Today")))</syntaxhighlight>


Using the clojure.string library:
Using the clojure.string library:
<lang clojure>(clojure.string/join "." (clojure.string/split "Hello,How,Are,You,Today" #","))</lang>
<syntaxhighlight lang="clojure">(clojure.string/join "." (clojure.string/split "Hello,How,Are,You,Today" #","))</syntaxhighlight>


=={{header|CLU}}==
=={{header|CLU}}==
<lang clu>% This iterator splits the string on a given character,
<syntaxhighlight lang="clu">% This iterator splits the string on a given character,
% and returns each substring in order.
% and returns each substring in order.
tokenize = iter (s: string, c: char) yields (string)
tokenize = iter (s: string, c: char) yields (string)
Line 1,410: Line 1,410:
stream$putl(po, part || ".")
stream$putl(po, part || ".")
end
end
end start_up</lang>
end start_up</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello.
<pre>Hello.
Line 1,421: Line 1,421:
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.
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">
<lang COBOL>
identification division.
identification division.
program-id. tokenize.
program-id. tokenize.
Line 1,452: Line 1,452:
goback.
goback.
end program tokenize.
end program tokenize.
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,462: Line 1,462:
=={{header|CoffeeScript}}==
=={{header|CoffeeScript}}==


<lang coffeescript>
<syntaxhighlight lang="coffeescript">
arr = "Hello,How,Are,You,Today".split ","
arr = "Hello,How,Are,You,Today".split ","
console.log arr.join "."
console.log arr.join "."
</syntaxhighlight>
</lang>


=={{header|ColdFusion}}==
=={{header|ColdFusion}}==
=== Classic tag based CFML ===
=== Classic tag based CFML ===
<lang cfm>
<syntaxhighlight lang="cfm">
<cfoutput>
<cfoutput>
<cfset wordListTag = "Hello,How,Are,You,Today">
<cfset wordListTag = "Hello,How,Are,You,Today">
#Replace( wordListTag, ",", ".", "all" )#
#Replace( wordListTag, ",", ".", "all" )#
</cfoutput>
</cfoutput>
</syntaxhighlight>
</lang>
{{Output}}
{{Output}}
<pre>
<pre>
Line 1,481: Line 1,481:


=== Script Based CFML ===
=== Script Based CFML ===
<lang cfm><cfscript>
<syntaxhighlight lang="cfm"><cfscript>
wordList = "Hello,How,Are,You,Today";
wordList = "Hello,How,Are,You,Today";
splitList = replace( wordList, ",", ".", "all" );
splitList = replace( wordList, ",", ".", "all" );
writeOutput( splitList );
writeOutput( splitList );
</cfscript></lang>
</cfscript></syntaxhighlight>
{{Output}}
{{Output}}
<pre>
<pre>
Line 1,495: Line 1,495:
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.
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.


<lang lisp>(defun comma-split (string)
<syntaxhighlight lang="lisp">(defun comma-split (string)
(loop for start = 0 then (1+ finish)
(loop for start = 0 then (1+ finish)
for finish = (position #\, string :start start)
for finish = (position #\, string :start start)
Line 1,502: Line 1,502:


(defun write-with-periods (strings)
(defun write-with-periods (strings)
(format t "~{~A~^.~}" strings))</lang>
(format t "~{~A~^.~}" strings))</syntaxhighlight>


=={{header|Cowgol}}==
=={{header|Cowgol}}==
<lang cowgol>include "cowgol.coh";
<syntaxhighlight lang="cowgol">include "cowgol.coh";
include "strings.coh";
include "strings.coh";


Line 1,544: Line 1,544:
print(".\n");
print(".\n");
i := i + 1;
i := i + 1;
end loop;</lang>
end loop;</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello.
<pre>Hello.
Line 1,553: Line 1,553:


=={{header|Crystal}}==
=={{header|Crystal}}==
<lang crystal>puts "Hello,How,Are,You,Today".split(',').join('.')</lang>
<syntaxhighlight lang="crystal">puts "Hello,How,Are,You,Today".split(',').join('.')</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello.How.Are.You.Today</pre>
<pre>Hello.How.Are.You.Today</pre>


=={{header|D}}==
=={{header|D}}==
<lang d>void main() {
<syntaxhighlight lang="d">void main() {
import std.stdio, std.string;
import std.stdio, std.string;


"Hello,How,Are,You,Today".split(',').join('.').writeln;
"Hello,How,Are,You,Today".split(',').join('.').writeln;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello.How.Are.You.Today</pre>
<pre>Hello.How.Are.You.Today</pre>
Line 1,569: Line 1,569:
=== Using String.split ===
=== Using String.split ===
{{libheader| System.SysUtils}}
{{libheader| System.SysUtils}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Tokenize_a_string;
program Tokenize_a_string;


Line 1,587: Line 1,587:
end.
end.


</syntaxhighlight>
</lang>


=== Using TStringList ===
=== Using TStringList ===
<syntaxhighlight lang="delphi">
<lang Delphi>
program TokenizeString;
program TokenizeString;


Line 1,623: Line 1,623:


end.
end.
</syntaxhighlight>
</lang>


The result is:
The result is:


<syntaxhighlight lang="delphi">
<lang Delphi>
Hello
Hello
How
How
Line 1,633: Line 1,633:
You
You
Today
Today
</syntaxhighlight>
</lang>


=={{header|Dyalect}}==
=={{header|Dyalect}}==


<lang dyalect>var str = "Hello,How,Are,You,Today"
<syntaxhighlight lang="dyalect">var str = "Hello,How,Are,You,Today"
var strings = str.Split(',')
var strings = str.Split(',')
print(values: strings, separator: ".")</lang>
print(values: strings, separator: ".")</syntaxhighlight>


{{out}}
{{out}}
Line 1,646: Line 1,646:


=={{header|Déjà Vu}}==
=={{header|Déjà Vu}}==
<lang dejavu>!print join "." split "Hello,How,Are,You,Today" ","</lang>
<syntaxhighlight lang="dejavu">!print join "." split "Hello,How,Are,You,Today" ","</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello.How.Are.You.Today</pre>
<pre>Hello.How.Are.You.Today</pre>


=={{header|E}}==
=={{header|E}}==
<lang e>".".rjoin("Hello,How,Are,You,Today".split(","))</lang>
<syntaxhighlight lang="e">".".rjoin("Hello,How,Are,You,Today".split(","))</syntaxhighlight>


=={{header|Elena}}==
=={{header|Elena}}==
ELENA 4.x:
ELENA 4.x:
<lang elena>import system'routines;
<syntaxhighlight lang="elena">import system'routines;
import extensions;
import extensions;
Line 1,666: Line 1,666:
console.print(s,".")
console.print(s,".")
}
}
}</lang>
}</syntaxhighlight>


=={{header|Elixir}}==
=={{header|Elixir}}==
<lang elixir>
<syntaxhighlight lang="elixir">
tokens = String.split("Hello,How,Are,You,Today", ",")
tokens = String.split("Hello,How,Are,You,Today", ",")
IO.puts Enum.join(tokens, ".")
IO.puts Enum.join(tokens, ".")
</syntaxhighlight>
</lang>


=={{header|Erlang}}==
=={{header|Erlang}}==
<lang erlang>-module(tok).
<syntaxhighlight lang="erlang">-module(tok).
-export([start/0]).
-export([start/0]).


Line 1,681: Line 1,681:
Lst = string:tokens("Hello,How,Are,You,Today",","),
Lst = string:tokens("Hello,How,Are,You,Today",","),
io:fwrite("~s~n", [string:join(Lst,".")]),
io:fwrite("~s~n", [string:join(Lst,".")]),
ok.</lang>
ok.</syntaxhighlight>


=={{header|Euphoria}}==
=={{header|Euphoria}}==
<lang euphoria>function split(sequence s, integer c)
<syntaxhighlight lang="euphoria">function split(sequence s, integer c)
sequence out
sequence out
integer first, delim
integer first, delim
Line 1,705: Line 1,705:
for i = 1 to length(s) do
for i = 1 to length(s) do
puts(1, s[i] & ',')
puts(1, s[i] & ',')
end for</lang>
end for</syntaxhighlight>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>System.String.Join(".", "Hello,How,Are,You,Today".Split(','))</lang>
<syntaxhighlight lang="fsharp">System.String.Join(".", "Hello,How,Are,You,Today".Split(','))</syntaxhighlight>


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>"Hello,How,Are,You,Today" "," split "." join print</lang>
<syntaxhighlight lang="factor">"Hello,How,Are,You,Today" "," split "." join print</syntaxhighlight>


=={{header|Falcon}}==
=={{header|Falcon}}==
'''VBA/Python programmer's approach to this solution, not sure if it's the most falconic way'''
'''VBA/Python programmer's approach to this solution, not sure if it's the most falconic way'''
<lang falcon>
<syntaxhighlight lang="falcon">
/* created by Aykayayciti Earl Lamont Montgomery
/* created by Aykayayciti Earl Lamont Montgomery
April 9th, 2018 */
April 9th, 2018 */
Line 1,729: Line 1,729:


> b
> b
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,740: Line 1,740:
A string can be split on a given character, returning a list of the intervening strings.
A string can be split on a given character, returning a list of the intervening strings.


<lang fantom>
<syntaxhighlight lang="fantom">
class Main
class Main
{
{
Line 1,753: Line 1,753:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Fennel}}==
=={{header|Fennel}}==
{{trans|Lua}}
{{trans|Lua}}
<lang fennel>(fn string.split [self sep]
<syntaxhighlight lang="fennel">(fn string.split [self sep]
(let [pattern (string.format "([^%s]+)" sep)
(let [pattern (string.format "([^%s]+)" sep)
fields {}]
fields {}]
Line 1,764: Line 1,764:


(let [str "Hello,How,Are,You,Today"]
(let [str "Hello,How,Are,You,Today"]
(print (table.concat (str:split ",") ".")))</lang>
(print (table.concat (str:split ",") ".")))</syntaxhighlight>


=={{header|Forth}}==
=={{header|Forth}}==
There is no standard string split routine, but it is easily written. The results are saved temporarily to the dictionary.
There is no standard string split routine, but it is easily written. The results are saved temporarily to the dictionary.


<lang forth>: split ( str len separator len -- tokens count )
<syntaxhighlight lang="forth">: split ( str len separator len -- tokens count )
here >r 2swap
here >r 2swap
begin
begin
Line 1,786: Line 1,786:
1 ?do dup 2@ type ." ." cell+ cell+ loop 2@ type ;
1 ?do dup 2@ type ." ." cell+ cell+ loop 2@ type ;


s" Hello,How,Are,You,Today" s" ," split .tokens \ Hello.How.Are.You.Today</lang>
s" Hello,How,Are,You,Today" s" ," split .tokens \ Hello.How.Are.You.Today</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
{{works with|Fortran|90 and later}}
<lang fortran>PROGRAM Example
<syntaxhighlight lang="fortran">PROGRAM Example


CHARACTER(23) :: str = "Hello,How,Are,You,Today"
CHARACTER(23) :: str = "Hello,How,Are,You,Today"
Line 1,812: Line 1,812:
END DO
END DO
END PROGRAM Example</lang>
END PROGRAM Example</syntaxhighlight>


=={{header|Frink}}==
=={{header|Frink}}==
<lang frink>
<syntaxhighlight lang="frink">
println[join[".", split[",", "Hello,How,Are,You,Today"]]]
println[join[".", split[",", "Hello,How,Are,You,Today"]]]
</syntaxhighlight>
</lang>


=={{header|Gambas}}==
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=218e240236cdf1419a405abfed906ed3 Click this link to run this code]'''
'''[https://gambas-playground.proko.eu/?gist=218e240236cdf1419a405abfed906ed3 Click this link to run this code]'''
<lang gambas>Public Sub Main()
<syntaxhighlight lang="gambas">Public Sub Main()
Dim sString As String[] = Split("Hello,How,Are,You,Today")
Dim sString As String[] = Split("Hello,How,Are,You,Today")


Print sString.Join(".")
Print sString.Join(".")


End</lang>
End</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 1,833: Line 1,833:


=={{header|GAP}}==
=={{header|GAP}}==
<lang gap>SplitString("Hello,How,Are,You,Today", ",");
<syntaxhighlight lang="gap">SplitString("Hello,How,Are,You,Today", ",");
# [ "Hello", "How", "Are", "You", "Today" ]
# [ "Hello", "How", "Are", "You", "Today" ]


JoinStringsWithSeparator(last, ".");
JoinStringsWithSeparator(last, ".");
# "Hello.How.Are.You.Today"</lang>
# "Hello.How.Are.You.Today"</syntaxhighlight>


=={{header|Genie}}==
=={{header|Genie}}==
<lang genie>[indent=4]
<syntaxhighlight lang="genie">[indent=4]


init
init
Line 1,846: Line 1,846:
words:array of string[] = str.split(",")
words:array of string[] = str.split(",")
joined:string = string.joinv(".", words)
joined:string = string.joinv(".", words)
print joined</lang>
print joined</syntaxhighlight>


{{out}}
{{out}}
Line 1,854: Line 1,854:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 1,864: Line 1,864:
s := "Hello,How,Are,You,Today"
s := "Hello,How,Are,You,Today"
fmt.Println(strings.Join(strings.Split(s, ","), "."))
fmt.Println(strings.Join(strings.Split(s, ","), "."))
}</lang>
}</syntaxhighlight>


=={{header|Groovy}}==
=={{header|Groovy}}==
<lang groovy>println 'Hello,How,Are,You,Today'.split(',').join('.')</lang>
<syntaxhighlight lang="groovy">println 'Hello,How,Are,You,Today'.split(',').join('.')</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==
'''Using Data.Text'''
'''Using Data.Text'''


<lang haskell>{-# OPTIONS_GHC -XOverloadedStrings #-}
<syntaxhighlight lang="haskell">{-# OPTIONS_GHC -XOverloadedStrings #-}
import Data.Text (splitOn,intercalate)
import Data.Text (splitOn,intercalate)
import qualified Data.Text.IO as T (putStrLn)
import qualified Data.Text.IO as T (putStrLn)


main = T.putStrLn . intercalate "." $ splitOn "," "Hello,How,Are,You,Today"</lang>
main = T.putStrLn . intercalate "." $ splitOn "," "Hello,How,Are,You,Today"</syntaxhighlight>


Output: Hello.How.Are.You.Today
Output: Hello.How.Are.You.Today
Line 1,884: Line 1,884:
The necessary operations are unfortunately not in the standard library (yet), but simple to write:
The necessary operations are unfortunately not in the standard library (yet), but simple to write:


<lang haskell>splitBy :: (a -> Bool) -> [a] -> [[a]]
<syntaxhighlight lang="haskell">splitBy :: (a -> Bool) -> [a] -> [[a]]
splitBy _ [] = []
splitBy _ [] = []
splitBy f list = first : splitBy f (dropWhile f rest) where
splitBy f list = first : splitBy f (dropWhile f rest) where
Line 1,899: Line 1,899:
-- using regular expression to split:
-- using regular expression to split:
import Text.Regex
import Text.Regex
putStrLn $ joinWith "." $ splitRegex (mkRegex ",") $ "Hello,How,Are,You,Today"</lang>
putStrLn $ joinWith "." $ splitRegex (mkRegex ",") $ "Hello,How,Are,You,Today"</syntaxhighlight>


Tokenizing can also be realized by using unfoldr and break:
Tokenizing can also be realized by using unfoldr and break:
<lang Haskell>*Main> mapM_ putStrLn $ takeWhile (not.null) $ unfoldr (Just . second(drop 1). break (==',')) "Hello,How,Are,You,Today"
<syntaxhighlight lang="haskell">*Main> mapM_ putStrLn $ takeWhile (not.null) $ unfoldr (Just . second(drop 1). break (==',')) "Hello,How,Are,You,Today"
Hello
Hello
How
How
Are
Are
You
You
Today</lang>
Today</syntaxhighlight>
* You need to import the modules Data.List and Control.Arrow
* You need to import the modules Data.List and Control.Arrow


Line 1,913: Line 1,913:


=={{header|HicEst}}==
=={{header|HicEst}}==
<lang hicest>CHARACTER string="Hello,How,Are,You,Today", list
<syntaxhighlight lang="hicest">CHARACTER string="Hello,How,Are,You,Today", list


nWords = INDEX(string, ',', 256) + 1
nWords = INDEX(string, ',', 256) + 1
Line 1,925: Line 1,925:
DO i = 1, nWords
DO i = 1, nWords
WRITE(APPend) TRIM(CHAR(i, maxWordLength, list)), '.'
WRITE(APPend) TRIM(CHAR(i, maxWordLength, list)), '.'
ENDDO</lang>
ENDDO</syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==
<lang icon>procedure main()
<syntaxhighlight lang="icon">procedure main()
A := []
A := []
"Hello,How,Are,You,Today" ? {
"Hello,How,Are,You,Today" ? {
Line 1,936: Line 1,936:
every writes(!A,".")
every writes(!A,".")
write()
write()
end</lang>
end</syntaxhighlight>


{{out}}
{{out}}
Line 1,946: Line 1,946:


A Unicon-specific solution is:
A Unicon-specific solution is:
<lang unicon>import util
<syntaxhighlight lang="unicon">import util


procedure main()
procedure main()
Line 1,952: Line 1,952:
every writes(!A,".")
every writes(!A,".")
write()
write()
end</lang>
end</syntaxhighlight>


One wonders what the expected output should be with the input string ",,,,".
One wonders what the expected output should be with the input string ",,,,".


=={{header|Io}}==
=={{header|Io}}==
<lang io>"Hello,How,Are,You,Today" split(",") join(".") println</lang>
<syntaxhighlight lang="io">"Hello,How,Are,You,Today" split(",") join(".") println</syntaxhighlight>


=={{header|J}}==
=={{header|J}}==
<lang j> s=: 'Hello,How,Are,You,Today'
<syntaxhighlight lang="j"> s=: 'Hello,How,Are,You,Today'
] t=: <;._1 ',',s
] t=: <;._1 ',',s
+-----+---+---+---+-----+
+-----+---+---+---+-----+
Line 1,969: Line 1,969:


'.' (I.','=s)}s NB. two steps combined
'.' (I.','=s)}s NB. two steps combined
Hello.How.Are.You.Today</lang>
Hello.How.Are.You.Today</syntaxhighlight>


Alternatively using the system library/script <tt>strings</tt>
Alternatively using the system library/script <tt>strings</tt>
<lang j> require 'strings'
<syntaxhighlight lang="j"> require 'strings'
',' splitstring s
',' splitstring s
+-----+---+---+---+-----+
+-----+---+---+---+-----+
Line 1,979: Line 1,979:


'.' joinstring ',' splitstring s
'.' joinstring ',' splitstring s
Hello.How.Are.You.Today</lang>
Hello.How.Are.You.Today</syntaxhighlight>


<tt>splitstring</tt> and <tt>joinstring</tt> also work with longer "delimiters":
<tt>splitstring</tt> and <tt>joinstring</tt> also work with longer "delimiters":
<lang j> '"'([ ,~ ,) '","' joinstring ',' splitstring s
<syntaxhighlight lang="j"> '"'([ ,~ ,) '","' joinstring ',' splitstring s
"Hello","How","Are","You","Today"</lang>
"Hello","How","Are","You","Today"</syntaxhighlight>


But, of course, this could be solved with simple string replacement:
But, of course, this could be solved with simple string replacement:


<lang J> rplc&',.' s
<syntaxhighlight lang="j"> rplc&',.' s
Hello.How.Are.You.Today</lang>
Hello.How.Are.You.Today</syntaxhighlight>


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.
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 1,994: Line 1,994:
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:
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:


<lang J> fn;._2 string,','</lang>
<syntaxhighlight lang="j"> fn;._2 string,','</syntaxhighlight>


Here '''fn''' is applied to each ',' delimited substring and the results are assembled into an array.
Here '''fn''' is applied to each ',' delimited substring and the results are assembled into an array.


Or, factoring out the names:
Or, factoring out the names:
<lang J> fn ((;._2)(@(,&','))) string</lang>
<syntaxhighlight lang="j"> fn ((;._2)(@(,&','))) string</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
Line 2,010: Line 2,010:
{{works with|Java|1.8+}}
{{works with|Java|1.8+}}


<lang java5>String toTokenize = "Hello,How,Are,You,Today";
<syntaxhighlight lang="java5">String toTokenize = "Hello,How,Are,You,Today";
System.out.println(String.join(".", toTokenize.split(",")));</lang>
System.out.println(String.join(".", toTokenize.split(",")));</syntaxhighlight>


{{works with|Java|1.4+}}
{{works with|Java|1.4+}}
<lang java5>String toTokenize = "Hello,How,Are,You,Today";
<syntaxhighlight lang="java5">String toTokenize = "Hello,How,Are,You,Today";


String words[] = toTokenize.split(",");//splits on one comma, multiple commas yield multiple splits
String words[] = toTokenize.split(",");//splits on one comma, multiple commas yield multiple splits
Line 2,020: Line 2,020:
for(int i=0; i<words.length; i++) {
for(int i=0; i<words.length; i++) {
System.out.print(words[i] + ".");
System.out.print(words[i] + ".");
}</lang>
}</syntaxhighlight>


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.
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+}}
{{works with|Java|1.0+}}
<lang java5>String toTokenize = "Hello,How,Are,You,Today";
<syntaxhighlight lang="java5">String toTokenize = "Hello,How,Are,You,Today";


StringTokenizer tokenizer = new StringTokenizer(toTokenize, ",");
StringTokenizer tokenizer = new StringTokenizer(toTokenize, ",");
while(tokenizer.hasMoreTokens()) {
while(tokenizer.hasMoreTokens()) {
System.out.print(tokenizer.nextToken() + ".");
System.out.print(tokenizer.nextToken() + ".");
}</lang>
}</syntaxhighlight>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
{{works with|Firefox|2.0}}
{{works with|Firefox|2.0}}


<lang javascript>alert( "Hello,How,Are,You,Today".split(",").join(".") );</lang>
<syntaxhighlight lang="javascript">alert( "Hello,How,Are,You,Today".split(",").join(".") );</syntaxhighlight>


=={{header|jq}}==
=={{header|jq}}==
<lang jq>split(",") | join(".")</lang>Example:<lang sh>$ jq -r 'split(",") | join(".")'
<syntaxhighlight lang="jq">split(",") | join(".")</syntaxhighlight>Example:<syntaxhighlight lang="sh">$ jq -r 'split(",") | join(".")'
"Hello,How,Are,You,Today"
"Hello,How,Are,You,Today"
Hello.How.Are.You.Today</lang>
Hello.How.Are.You.Today</syntaxhighlight>


=={{header|Jsish}}==
=={{header|Jsish}}==
Being in the ECMAScript family, Jsi is blessed with many easy to use character, string and array manipulation routines.
Being in the ECMAScript family, Jsi is blessed with many easy to use character, string and array manipulation routines.


<lang javascript>puts('Hello,How,Are,You,Today'.split(',').join('.'))</lang>
<syntaxhighlight lang="javascript">puts('Hello,How,Are,You,Today'.split(',').join('.'))</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello.How.Are.You.Today</pre>
<pre>Hello.How.Are.You.Today</pre>


=={{header|Julia}}==
=={{header|Julia}}==
<syntaxhighlight lang="julia">
<lang Julia>
s = "Hello,How,Are,You,Today"
s = "Hello,How,Are,You,Today"
a = split(s, ",")
a = split(s, ",")
Line 2,058: Line 2,058:
println("Splits into ", a)
println("Splits into ", a)
println("Reconstitutes to \"", t, "\"")
println("Reconstitutes to \"", t, "\"")
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 2,068: Line 2,068:


=={{header|K}}==
=={{header|K}}==
<lang K>words: "," \: "Hello,How,Are,You,Today"
<syntaxhighlight lang="k">words: "," \: "Hello,How,Are,You,Today"
"." /: words</lang>
"." /: words</syntaxhighlight>


{{out}}
{{out}}
Line 2,077: Line 2,077:


=={{header|Klingphix}}==
=={{header|Klingphix}}==
<lang Klingphix>( "Hello,How,Are,You,Today" "," ) split len [ get print "." print ] for
<syntaxhighlight lang="klingphix">( "Hello,How,Are,You,Today" "," ) split len [ get print "." print ] for


nl "End " input</lang>
nl "End " input</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello.How.Are.You.Today.
<pre>Hello.How.Are.You.Today.
Line 2,086: Line 2,086:
=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{works with|Kotlin|1.0b4}}
{{works with|Kotlin|1.0b4}}
<lang scala>fun main(args: Array<String>) {
<syntaxhighlight lang="scala">fun main(args: Array<String>) {
val input = "Hello,How,Are,You,Today"
val input = "Hello,How,Are,You,Today"
println(input.split(',').joinToString("."))
println(input.split(',').joinToString("."))
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello.How.Are.You.Today</pre>
<pre>Hello.How.Are.You.Today</pre>


=={{header|Ksh}}==
=={{header|Ksh}}==
<lang ksh>
<syntaxhighlight lang="ksh">
#!/bin/ksh
#!/bin/ksh


Line 2,125: Line 2,125:
######
######


_tokenize "${string}" "${inputdelim}" "${outputdelim}"</lang>
_tokenize "${string}" "${inputdelim}" "${outputdelim}"</syntaxhighlight>
{{out}}<pre>Hello.How.Are.You.Today</pre>
{{out}}<pre>Hello.How.Are.You.Today</pre>


Line 2,133: Line 2,133:


=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
<lang scheme>
<syntaxhighlight lang="scheme">
{S.replace , by . in Hello,How,Are,You,Today}.
{S.replace , by . in Hello,How,Are,You,Today}.
-> Hello.How.Are.You.Today.
-> Hello.How.Are.You.Today.
</syntaxhighlight>
</lang>


=={{header|Lang5}}==
=={{header|Lang5}}==
<lang lang5>'Hello,How,Are,You,Today ', split '. join .</lang>
<syntaxhighlight lang="lang5">'Hello,How,Are,You,Today ', split '. join .</syntaxhighlight>


=={{header|LDPL}}==
=={{header|LDPL}}==
<lang ldpl>
<syntaxhighlight lang="ldpl">
DATA:
DATA:
explode/words is text vector
explode/words is text vector
Line 2,194: Line 2,194:
add 1 and i in i
add 1 and i in i
repeat
repeat
</syntaxhighlight>
</lang>


=={{header|LFE}}==
=={{header|LFE}}==


<lang lisp>
<syntaxhighlight lang="lisp">
> (set split (string:tokens "Hello,How,Are,You,Today" ","))
> (set split (string:tokens "Hello,How,Are,You,Today" ","))
("Hello" "How" "Are" "You" "Today")
("Hello" "How" "Are" "You" "Today")
> (string:join split ".")
> (string:join split ".")
"Hello.How.Are.You.Today"
"Hello.How.Are.You.Today"
</syntaxhighlight>
</lang>


=={{header|Lingo}}==
=={{header|Lingo}}==
<lang lingo>input = "Hello,How,Are,You,Today"
<syntaxhighlight lang="lingo">input = "Hello,How,Are,You,Today"
_player.itemDelimiter = ","
_player.itemDelimiter = ","
output = ""
output = ""
Line 2,214: Line 2,214:
delete the last char of output
delete the last char of output
put output
put output
-- "Hello.How.Are.You.Today"</lang>
-- "Hello.How.Are.You.Today"</syntaxhighlight>


=={{header|Logo}}==
=={{header|Logo}}==
{{works with|UCB Logo}}
{{works with|UCB Logo}}
<lang logo>to split :str :sep
<syntaxhighlight lang="logo">to split :str :sep
output parse map [ifelse ? = :sep ["| |] [?]] :str
output parse map [ifelse ? = :sep ["| |] [?]] :str
end</lang>
end</syntaxhighlight>


This form is more robust, doing the right thing if there are embedded spaces.
This form is more robust, doing the right thing if there are embedded spaces.
<lang logo>to split :str :by [:acc []] [:w "||]
<syntaxhighlight lang="logo">to split :str :by [:acc []] [:w "||]
if empty? :str [output lput :w :acc]
if empty? :str [output lput :w :acc]
ifelse equal? first :str :by ~
ifelse equal? first :str :by ~
[output (split butfirst :str :by lput :w :acc)] ~
[output (split butfirst :str :by lput :w :acc)] ~
[output (split butfirst :str :by :acc lput first :str :w)]
[output (split butfirst :str :by :acc lput first :str :w)]
end</lang>
end</syntaxhighlight>


<lang logo>? show split "Hello,How,Are,You,Today ",
<syntaxhighlight lang="logo">? show split "Hello,How,Are,You,Today ",
[Hello How Are You Today]</lang>
[Hello How Are You Today]</syntaxhighlight>


=={{header|Logtalk}}==
=={{header|Logtalk}}==
Using Logtalk built-in support for Definite Clause Grammars (DCGs) and representing the strings as atoms for readbility:
Using Logtalk built-in support for Definite Clause Grammars (DCGs) and representing the strings as atoms for readbility:
<lang logtalk>
<syntaxhighlight lang="logtalk">
:- object(spliting).
:- object(spliting).


Line 2,258: Line 2,258:


:- end_object.
:- end_object.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,268: Line 2,268:
=={{header|Lua}}==
=={{header|Lua}}==
Split function callously stolen from the lua-users wiki
Split function callously stolen from the lua-users wiki
<lang Lua>function string:split (sep)
<syntaxhighlight lang="lua">function string:split (sep)
local sep, fields = sep or ":", {}
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
local pattern = string.format("([^%s]+)", sep)
Line 2,276: Line 2,276:


local str = "Hello,How,Are,You,Today"
local str = "Hello,How,Are,You,Today"
print(table.concat(str:split(","), "."))</lang>
print(table.concat(str:split(","), "."))</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello.How.Are.You.Today</pre>
<pre>Hello.How.Are.You.Today</pre>


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Module CheckIt {
Function Tokenize$(s){
Function Tokenize$(s){
Line 2,294: Line 2,294:
}
}
Checkit
Checkit
</syntaxhighlight>
</lang>


=={{header|M4}}==
=={{header|M4}}==
<lang M4>define(`s',`Hello,How,Are,You,Today')
<syntaxhighlight lang="m4">define(`s',`Hello,How,Are,You,Today')
define(`set',`define(`$1[$2]',`$3')')
define(`set',`define(`$1[$2]',`$3')')
define(`get',`defn($1[$2])')
define(`get',`defn($1[$2])')
Line 2,307: Line 2,307:
define(`show',
define(`show',
`ifelse(eval(j<n),1,`get(a,j).`'define(`j',incr(j))`'show')')
`ifelse(eval(j<n),1,`get(a,j).`'define(`j',incr(j))`'show')')
show</lang>
show</syntaxhighlight>


{{out}}
{{out}}
Line 2,315: Line 2,315:


=={{header|Maple}}==
=={{header|Maple}}==
<lang Maple>StringTools:-Join(StringTools:-Split("Hello,How,Are,You,Today", ","),".");</lang>
<syntaxhighlight lang="maple">StringTools:-Join(StringTools:-Split("Hello,How,Are,You,Today", ","),".");</syntaxhighlight>
{{Out|Output}}
{{Out|Output}}
<pre>"Hello.How.Are.You.Today"</pre>
<pre>"Hello.How.Are.You.Today"</pre>


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>StringJoin@StringSplit["Hello,How,Are,You,Today", "," -> "."]</lang>
<syntaxhighlight lang="mathematica">StringJoin@StringSplit["Hello,How,Are,You,Today", "," -> "."]</syntaxhighlight>


=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==
<syntaxhighlight lang="matlab">
<lang Matlab>
s=strsplit('Hello,How,Are,You,Today',',')
s=strsplit('Hello,How,Are,You,Today',',')
fprintf(1,'%s.',s{:})
fprintf(1,'%s.',s{:})
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 2,334: Line 2,334:


=={{header|Maxima}}==
=={{header|Maxima}}==
<lang Maxima>l: split("Hello,How,Are,You,Today", ",")$
<syntaxhighlight lang="maxima">l: split("Hello,How,Are,You,Today", ",")$
printf(true, "~{~a~^.~}~%", l)$</lang>
printf(true, "~{~a~^.~}~%", l)$</syntaxhighlight>


=={{header|MAXScript}}==
=={{header|MAXScript}}==
<lang maxscript>output = ""
<syntaxhighlight lang="maxscript">output = ""
for word in (filterString "Hello,How,Are,You,Today" ",") do
for word in (filterString "Hello,How,Are,You,Today" ",") do
(
(
output += (word + ".")
output += (word + ".")
)
)
format "%\n" output</lang>
format "%\n" output</syntaxhighlight>


=={{header|Mercury}}==
=={{header|Mercury}}==
<lang>
<syntaxhighlight lang="text">
:- module string_tokenize.
:- module string_tokenize.
:- interface.
:- interface.
Line 2,359: Line 2,359:
Tokens = string.split_at_char((','), "Hello,How,Are,You,Today"),
Tokens = string.split_at_char((','), "Hello,How,Are,You,Today"),
io.write_list(Tokens, ".", io.write_string, !IO),
io.write_list(Tokens, ".", io.write_string, !IO),
io.nl(!IO).</lang>
io.nl(!IO).</syntaxhighlight>


=={{header|min}}==
=={{header|min}}==
{{works with|min|0.19.3}}
{{works with|min|0.19.3}}
<lang min>"Hello,How,Are,You,Today" "," split "." join print</lang>
<syntaxhighlight lang="min">"Hello,How,Are,You,Today" "," split "." join print</syntaxhighlight>


=={{header|MiniScript}}==
=={{header|MiniScript}}==
<lang MiniScript>tokens = "Hello,How,Are,You,Today".split(",")
<syntaxhighlight lang="miniscript">tokens = "Hello,How,Are,You,Today".split(",")
print tokens.join(".")</lang>
print tokens.join(".")</syntaxhighlight>


=={{header|MMIX}}==
=={{header|MMIX}}==
<lang mmix>sep IS ','
<syntaxhighlight lang="mmix">sep IS ','
EOS IS 0
EOS IS 0
NL IS 10
NL IS 10
Line 2,423: Line 2,423:
LDBU t,tp
LDBU t,tp
PBNZ t,2B % UNTIL EOB(uffer)
PBNZ t,2B % UNTIL EOB(uffer)
TRAP 0,Halt,0</lang>
TRAP 0,Halt,0</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,435: Line 2,435:


=={{header|Modula-3}}==
=={{header|Modula-3}}==
<lang modula3>MODULE Tokenize EXPORTS Main;
<syntaxhighlight lang="modula3">MODULE Tokenize EXPORTS Main;


IMPORT IO, TextConv;
IMPORT IO, TextConv;
Line 2,452: Line 2,452:
END;
END;
IO.Put("\n");
IO.Put("\n");
END Tokenize.</lang>
END Tokenize.</syntaxhighlight>


=={{header|MUMPS}}==
=={{header|MUMPS}}==
<lang MUMPS>TOKENS
<syntaxhighlight lang="mumps">TOKENS
NEW I,J,INP
NEW I,J,INP
SET INP="Hello,how,are,you,today"
SET INP="Hello,how,are,you,today"
Line 2,461: Line 2,461:
NEW J FOR J=1:1:I WRITE INP(J) WRITE:J'=I "."
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"
KILL I,J,INP // Kill is optional. "New" variables automatically are killed on "Quit"
QUIT</lang>
QUIT</syntaxhighlight>


In use:
In use:
Line 2,468: Line 2,468:


=={{header|Nanoquery}}==
=={{header|Nanoquery}}==
<lang nanoquery>for word in "Hello,How,Are,You,Today".split(",")
<syntaxhighlight lang="nanoquery">for word in "Hello,How,Are,You,Today".split(",")
print word + "."
print word + "."
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello.How.Are.You.Today.</pre>
<pre>Hello.How.Are.You.Today.</pre>


=={{header|Nemerle}}==
=={{header|Nemerle}}==
<lang Nemerle>using System;
<syntaxhighlight lang="nemerle">using System;
using System.Console;
using System.Console;
using Nemerle.Utility.NString;
using Nemerle.Utility.NString;
Line 2,488: Line 2,488:
// a quick in place list comprehension takes care of that
// a quick in place list comprehension takes care of that
}
}
}</lang>
}</syntaxhighlight>


=={{header|NetRexx}}==
=={{header|NetRexx}}==
<lang NetRexx>/*NetRexx program *****************************************************
<syntaxhighlight lang="netrexx">/*NetRexx program *****************************************************
* 20.08.2012 Walter Pachl derived from REXX Version 3
* 20.08.2012 Walter Pachl derived from REXX Version 3
**********************************************************************/
**********************************************************************/
Line 2,502: Line 2,502:
Say ss.word(i)'.'
Say ss.word(i)'.'
End
End
Say 'End-of-list.'</lang>
Say 'End-of-list.'</syntaxhighlight>
Output as in REXX version
Output as in REXX version


=={{header|NewLISP}}==
=={{header|NewLISP}}==
<lang NewLISP>(print (join (parse "Hello,How,Are,You,Today" ",") "."))</lang>
<syntaxhighlight lang="newlisp">(print (join (parse "Hello,How,Are,You,Today" ",") "."))</syntaxhighlight>


=={{header|Nial}}==
=={{header|Nial}}==
Line 2,514: Line 2,514:
Define Array with input string:
Define Array with input string:


<lang Nial> s := 'Hello,How,Are,You,Today'
<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|
|H|e|l|l|o|,|H|o|w|,|A|r|e|,|Y|o|u|,|T|o|d|a|y|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</lang>
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</syntaxhighlight>


Split string at the commas:
Split string at the commas:


<lang Nial> t := s eachall = `, cut s
<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||
||H|e|l|l|o|||H|o|w|||A|r|e|||Y|o|u|||T|o|d|a|y||
|+-+-+-+-+-+|+-+-+-+|+-+-+-+|+-+-+-+|+-+-+-+-+-+|
|+-+-+-+-+-+|+-+-+-+|+-+-+-+|+-+-+-+|+-+-+-+-+-+|
+-----------+-------+-------+-------+-----------+</lang>
+-----------+-------+-------+-------+-----------+</syntaxhighlight>


Join string with <code>.</code> and remove last <code>.</code>
Join string with <code>.</code> and remove last <code>.</code>


<lang Nial> u := front content (cart t `.)
<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|
|H|e|l|l|o|.|H|o|w|.|A|r|e|.|Y|o|u|.|T|o|d|a|y|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</lang>
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</syntaxhighlight>


Less cluttered display, using <code>set "sketch;set "nodecor</code> display switches.
Less cluttered display, using <code>set "sketch;set "nodecor</code> display switches.


<lang Nial> s:='Hello,How,Are,You,Today'
<syntaxhighlight lang="nial"> s:='Hello,How,Are,You,Today'
Hello,How,Are,You,Today
Hello,How,Are,You,Today
t:= s eachall = `, cut s
t:= s eachall = `, cut s
Line 2,544: Line 2,544:
+-----+---+---+---+-----+
+-----+---+---+---+-----+
u:=front content (cart t `.)
u:=front content (cart t `.)
Hello.How.Are.You.Today</lang>
Hello.How.Are.You.Today</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
<lang nim>import strutils
<syntaxhighlight lang="nim">import strutils


let text = "Hello,How,Are,You,Today"
let text = "Hello,How,Are,You,Today"
let tokens = text.split(',')
let tokens = text.split(',')
echo tokens.join(".")</lang>
echo tokens.join(".")</syntaxhighlight>


{{out}}
{{out}}
Line 2,557: Line 2,557:


=={{header|Objeck}}==
=={{header|Objeck}}==
<lang objeck>
<syntaxhighlight lang="objeck">
class Parse {
class Parse {
function : Main(args : String[]) ~ Nil {
function : Main(args : String[]) ~ Nil {
Line 2,565: Line 2,565:
};
};
}
}
}</lang>
}</syntaxhighlight>


=={{header|Objective-C}}==
=={{header|Objective-C}}==
Line 2,572: Line 2,572:
{{works with|Cocoa}}
{{works with|Cocoa}}


<lang objc>NSString *text = @"Hello,How,Are,You,Today";
<syntaxhighlight lang="objc">NSString *text = @"Hello,How,Are,You,Today";
NSArray *tokens = [text componentsSeparatedByString:@","];
NSArray *tokens = [text componentsSeparatedByString:@","];
NSString *result = [tokens componentsJoinedByString:@"."];
NSString *result = [tokens componentsJoinedByString:@"."];
NSLog(result);</lang>
NSLog(result);</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==
To split on a single-character separator:
To split on a single-character separator:
<lang ocaml>let words = String.split_on_char ',' "Hello,How,Are,You,Today" in
<syntaxhighlight lang="ocaml">let words = String.split_on_char ',' "Hello,How,Are,You,Today" in
String.concat "." words
String.concat "." words
</syntaxhighlight>
</lang>


The function split_on_char has been introduced in OCaml 4.04. In previous versions, it could be implemented by:
The function split_on_char has been introduced in OCaml 4.04. In previous versions, it could be implemented by:


<lang ocaml>let split_on_char sep s =
<syntaxhighlight lang="ocaml">let split_on_char sep s =
let r = ref [] in
let r = ref [] in
let j = ref (String.length s) in
let j = ref (String.length s) in
Line 2,594: Line 2,594:
end
end
done;
done;
String.sub s 0 !j :: !r</lang>
String.sub s 0 !j :: !r</syntaxhighlight>


=={{header|Oforth}}==
=={{header|Oforth}}==


<lang Oforth>"Hello,How,Are,You,Today" wordsWith(',') println</lang>
<syntaxhighlight lang="oforth">"Hello,How,Are,You,Today" wordsWith(',') println</syntaxhighlight>


{{out}}
{{out}}
Line 2,606: Line 2,606:


=={{header|ooRexx}}==
=={{header|ooRexx}}==
<lang ooRexx>text='Hello,How,Are,You,Today'
<syntaxhighlight lang="oorexx">text='Hello,How,Are,You,Today'
do while text \= ''
do while text \= ''
parse var text word1 ',' text
parse var text word1 ',' text
call charout 'STDOUT:',word1'.'
call charout 'STDOUT:',word1'.'
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello.How.Are.You.Today.</pre>
<pre>Hello.How.Are.You.Today.</pre>


=={{header|OpenEdge/Progress}}==
=={{header|OpenEdge/Progress}}==
<lang progress>FUNCTION tokenizeString RETURNS CHAR (
<syntaxhighlight lang="progress">FUNCTION tokenizeString RETURNS CHAR (
i_c AS CHAR
i_c AS CHAR
):
):
Line 2,638: Line 2,638:
MESSAGE
MESSAGE
tokenizeString( "Hello,How,Are,You,Today" )
tokenizeString( "Hello,How,Are,You,Today" )
VIEW-AS ALERT-BOX.</lang>
VIEW-AS ALERT-BOX.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,651: Line 2,651:


=={{header|Oz}}==
=={{header|Oz}}==
<lang oz>for T in {String.tokens "Hello,How,Are,You,Today" &,} do
<syntaxhighlight lang="oz">for T in {String.tokens "Hello,How,Are,You,Today" &,} do
{System.printInfo T#"."}
{System.printInfo T#"."}
end</lang>
end</syntaxhighlight>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
Line 2,663: Line 2,663:
{{Works with|PARI/GP|2.7.4 and above}}
{{Works with|PARI/GP|2.7.4 and above}}


<lang parigp>
<syntaxhighlight lang="parigp">
\\ Tokenize a string str according to 1 character delimiter d. Return a list of tokens.
\\ 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
\\ Using ssubstr() from http://rosettacode.org/wiki/Substring#PARI.2FGP
Line 2,681: Line 2,681:
print("3.",tokenize(",Hello,,How,Are,You,Today",","));
print("3.",tokenize(",Hello,,How,Are,You,Today",","));
}
}
</lang>
</syntaxhighlight>


{{Output}}
{{Output}}
Line 2,699: Line 2,699:
{{Works with|PARI/GP|2.7.4 and above}}
{{Works with|PARI/GP|2.7.4 and above}}


<lang parigp>
<syntaxhighlight lang="parigp">
\\ Tokenize a string str according to 1 character delimiter d. Return a list of tokens.
\\ 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
\\ Using ssubstr() from http://rosettacode.org/wiki/Substring#PARI.2FGP
Line 2,728: Line 2,728:
print("7. 0 pp: ", stok("",","));
print("7. 0 pp: ", stok("",","));
}
}
</lang>
</syntaxhighlight>


{{Output}}
{{Output}}
Line 2,744: Line 2,744:
=={{header|Pascal}}==
=={{header|Pascal}}==
{{works with|Free_Pascal}}
{{works with|Free_Pascal}}
<lang pascal>program TokenizeString;
<syntaxhighlight lang="pascal">program TokenizeString;


{$mode objfpc}{$H+}
{$mode objfpc}{$H+}
Line 2,768: Line 2,768:
Tokens.Free;
Tokens.Free;
end;
end;
end.</lang>
end.</syntaxhighlight>


The result is:
The result is:
Line 2,775: Line 2,775:


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>print join('.', split /,/, 'Hello,How,Are,You,Today'), "\n";</lang>
<syntaxhighlight lang="perl">print join('.', split /,/, 'Hello,How,Are,You,Today'), "\n";</syntaxhighlight>
CLI one-liner form:
CLI one-liner form:
<lang perl>echo "Hello,How,Are,You,Today" | perl -aplF/,/ -e '$" = "."; $_ = "@F";'</lang>
<syntaxhighlight lang="perl">echo "Hello,How,Are,You,Today" | perl -aplF/,/ -e '$" = "."; $_ = "@F";'</syntaxhighlight>
which is a compact way of telling Perl to do
which is a compact way of telling Perl to do
<lang perl>BEGIN { $/ = "\n"; $\ = "\n"; }
<syntaxhighlight lang="perl">BEGIN { $/ = "\n"; $\ = "\n"; }
LINE: while (defined($_ = <ARGV>)) {
LINE: while (defined($_ = <ARGV>)) {
chomp $_;
chomp $_;
Line 2,788: Line 2,788:
continue {
continue {
die "-p destination: $!\n" unless print $_;
die "-p destination: $!\n" unless print $_;
}</lang>
}</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<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>
<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>-->
<!--</syntaxhighlight>-->
{{Out}}
{{Out}}
<pre>
<pre>
Line 2,800: Line 2,800:


=={{header|Phixmonti}}==
=={{header|Phixmonti}}==
<lang Phixmonti>/# "Hello,How,Are,You,Today" "," "." subst print #/
<syntaxhighlight lang="phixmonti">/# "Hello,How,Are,You,Today" "," "." subst print #/
"Hello,How,Are,You,Today" "," " " subst split len for get print "." print endfor</lang>
"Hello,How,Are,You,Today" "," " " subst split len for get print "." print endfor</syntaxhighlight>


=={{header|PHP}}==
=={{header|PHP}}==
{{works with|PHP|5.x}}
{{works with|PHP|5.x}}


<lang php><?php
<syntaxhighlight lang="php"><?php
$str = 'Hello,How,Are,You,Today';
$str = 'Hello,How,Are,You,Today';
echo implode('.', explode(',', $str));
echo implode('.', explode(',', $str));
?></lang>
?></syntaxhighlight>


=={{header|Picat}}==
=={{header|Picat}}==
Using the built-in functions <code>split/2</code> and <code>join/2</code>.
Using the built-in functions <code>split/2</code> and <code>join/2</code>.
<lang Picat>import util.
<syntaxhighlight lang="picat">import util.


go =>
go =>
Line 2,822: Line 2,822:


% As a one liner:
% As a one liner:
S.split(",").join(".").println().</lang>
S.split(",").join(".").println().</syntaxhighlight>


{{out}}
{{out}}
Line 2,830: Line 2,830:


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(mapcar pack
<syntaxhighlight lang="picolisp">(mapcar pack
(split (chop "Hello,How,Are,You,Today") ",") )</lang>
(split (chop "Hello,How,Are,You,Today") ",") )</syntaxhighlight>


=={{header|Pike}}==
=={{header|Pike}}==
<lang pike>("Hello,How,Are,You,Today" / ",") * ".";</lang>
<syntaxhighlight lang="pike">("Hello,How,Are,You,Today" / ",") * ".";</syntaxhighlight>


=={{header|PL/I}}==
=={{header|PL/I}}==
<lang pli>tok: Proc Options(main);
<syntaxhighlight lang="pli">tok: Proc Options(main);
declare s character (100) initial ('Hello,How,Are,You,Today');
declare s character (100) initial ('Hello,How,Are,You,Today');
declare n fixed binary (31);
declare n fixed binary (31);
Line 2,859: Line 2,859:
put skip list (string(table));
put skip list (string(table));
end;
end;
end;</lang>
end;</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello.How.Are.You.Today</pre>
<pre>Hello.How.Are.You.Today</pre>


=={{header|PL/M}}==
=={{header|PL/M}}==
<lang plm>100H:
<syntaxhighlight lang="plm">100H:
/* CP/M CALLS */
/* CP/M CALLS */
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
Line 2,903: Line 2,903:


CALL EXIT;
CALL EXIT;
EOF;</lang>
EOF;</syntaxhighlight>
{{out}}
{{out}}
<pre>HELLO. HOW. ARE. YOU. TODAY. </pre>
<pre>HELLO. HOW. ARE. YOU. TODAY. </pre>


=={{header|Plain English}}==
=={{header|Plain English}}==
<lang plainenglish>To run:
<syntaxhighlight lang="plainenglish">To run:
Start up.
Start up.
Split "Hello,How,Are,You,Today" into some string things given the comma byte.
Split "Hello,How,Are,You,Today" into some string things given the comma byte.
Line 2,924: Line 2,924:
If the string thing's next is not nil, append the byte 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.
Put the string thing's next into the string thing.
Repeat.</lang>
Repeat.</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,937: Line 2,937:
First show the use of sysparse_string to break up a string and make a list of strings.
First show the use of sysparse_string to break up a string and make a list of strings.


<lang pop11>;;; Make a list of strings from a string using space as separator
<syntaxhighlight lang="pop11">;;; Make a list of strings from a string using space as separator
lvars list;
lvars list;
sysparse_string('the cat sat on the mat') -> list;
sysparse_string('the cat sat on the mat') -> list;
;;; print the list of strings
;;; print the list of strings
list =>
list =>
** [the cat sat on the mat]</lang>
** [the cat sat on the mat]</syntaxhighlight>


By giving it an extra parameter 'true' we can make it recognize numbers and produce a list of strings and numbers
By giving it an extra parameter 'true' we can make it recognize numbers and produce a list of strings and numbers


<lang pop11>lvars list;
<syntaxhighlight lang="pop11">lvars list;
sysparse_string('one 1 two 2 three 3 four 4', true) -> list;
sysparse_string('one 1 two 2 three 3 four 4', true) -> list;
;;; print the list of strings and numbers
;;; print the list of strings and numbers
Line 2,955: Line 2,955:
** <true>
** <true>
isinteger(list(2))=>
isinteger(list(2))=>
** <true></lang>
** <true></syntaxhighlight>


Now show some uses of the built in procedure sys_parse_string, which allows more options:
Now show some uses of the built in procedure sys_parse_string, which allows more options:


<lang pop11>;;; Make pop-11 print strings with quotes
<syntaxhighlight lang="pop11">;;; Make pop-11 print strings with quotes
true -> pop_pr_quotes;
true -> pop_pr_quotes;
;;;
;;;
Line 2,973: Line 2,973:
;;; print the list of strings
;;; print the list of strings
strings =>
strings =>
** ['Hello' 'How' 'Are' 'You' 'Today']</lang>
** ['Hello' 'How' 'Are' 'You' 'Today']</syntaxhighlight>


If {% ... %} were used instead of [% ... %] the result would be
If {% ... %} were used instead of [% ... %] the result would be
a vector (i.e. array) of strings rather than a list of strings.
a vector (i.e. array) of strings rather than a list of strings.


<lang pop11>{% sys_parse_string(str, `,`) %} -> strings;
<syntaxhighlight lang="pop11">{% sys_parse_string(str, `,`) %} -> strings;
;;; print the vector
;;; print the vector
strings =>
strings =>
** {'Hello' 'How' 'Are' 'You' 'Today'}</lang>
** {'Hello' 'How' 'Are' 'You' 'Today'}</syntaxhighlight>
It is also possible to give sys_parse_string a 'conversion' procedure, which is applied to each of the tokens.
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:
E.g. it could be used to produce a vector of numbers, using the conversion procedure 'strnumber', which converts a string to a number:


<lang pop11>lvars numbers;
<syntaxhighlight lang="pop11">lvars numbers;
{% sys_parse_string('100 101 102 103 99.9 99.999', strnumber) %} -> numbers;
{% sys_parse_string('100 101 102 103 99.9 99.999', strnumber) %} -> numbers;
;;; the result is a vector containing integers and floats,
;;; the result is a vector containing integers and floats,
;;; which can be printed thus:
;;; which can be printed thus:
numbers =>
numbers =>
** {100 101 102 103 99.9 99.999}</lang>
** {100 101 102 103 99.9 99.999}</syntaxhighlight>


Using lower level pop-11 facilities to tokenise the string:
Using lower level pop-11 facilities to tokenise the string:


<lang pop11>;;; Declare and initialize variables
<syntaxhighlight lang="pop11">;;; Declare and initialize variables
lvars str='Hello,How,Are,You,Today';
lvars str='Hello,How,Are,You,Today';
;;; Iterate over string
;;; Iterate over string
Line 3,012: Line 3,012:
endif;
endif;
;;; Reverse the list
;;; Reverse the list
rev(ls) -> ls;</lang>
rev(ls) -> ls;</syntaxhighlight>


Since the task requires to use array we convert list to array
Since the task requires to use array we convert list to array


<lang pop11>;;; Put list elements and lenght on the stack
<syntaxhighlight lang="pop11">;;; Put list elements and lenght on the stack
destlist(ls);
destlist(ls);
;;; Build a vector from them
;;; Build a vector from them
Line 3,024: Line 3,024:
printf(ar(i), '%s.');
printf(ar(i), '%s.');
endfor;
endfor;
printf('\n');</lang>
printf('\n');</syntaxhighlight>


We could use list directly for printing:
We could use list directly for printing:


<lang pop11>for i in ls do
<syntaxhighlight lang="pop11">for i in ls do
printf(i, '%s.');
printf(i, '%s.');
endfor;</lang>
endfor;</syntaxhighlight>


so the conversion to vector is purely to satisfy task formulation.
so the conversion to vector is purely to satisfy task formulation.
Line 3,036: Line 3,036:
=={{header|PowerShell}}==
=={{header|PowerShell}}==
{{works with|PowerShell|1}}
{{works with|PowerShell|1}}
<lang powershell>$words = "Hello,How,Are,You,Today".Split(',')
<syntaxhighlight lang="powershell">$words = "Hello,How,Are,You,Today".Split(',')
[string]::Join('.', $words)</lang>
[string]::Join('.', $words)</syntaxhighlight>


{{works with|PowerShell|2}}
{{works with|PowerShell|2}}
<lang powershell>$words = "Hello,How,Are,You,Today" -split ','
<syntaxhighlight lang="powershell">$words = "Hello,How,Are,You,Today" -split ','
$words -join '.'</lang>
$words -join '.'</syntaxhighlight>


{{works with|PowerShell|2}}
{{works with|PowerShell|2}}
The StringSplitOptions enumeration weeds out the return of empty elements.
The StringSplitOptions enumeration weeds out the return of empty elements.
<syntaxhighlight lang="powershell">
<lang PowerShell>
"Hello,How,Are,You,Today", ",,Hello,,Goodbye,," | ForEach-Object {($_.Split(',',[StringSplitOptions]::RemoveEmptyEntries)) -join "."}
"Hello,How,Are,You,Today", ",,Hello,,Goodbye,," | ForEach-Object {($_.Split(',',[StringSplitOptions]::RemoveEmptyEntries)) -join "."}
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 3,056: Line 3,056:
=={{header|Prolog}}==
=={{header|Prolog}}==
{{works with|SWI Prolog}}
{{works with|SWI Prolog}}
<lang prolog>splitup(Sep,[token(B)|BL]) --> splitup(Sep,B,BL).
<syntaxhighlight 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,[A|AL],B) --> [A], {\+ [A] = Sep }, splitup(Sep,AL,B).
splitup(Sep,[],[B|BL]) --> Sep, splitup(Sep,B,BL).
splitup(Sep,[],[B|BL]) --> Sep, splitup(Sep,B,BL).
Line 3,064: Line 3,064:
phrase(splitup(".",Tokens),Backtogether),
phrase(splitup(".",Tokens),Backtogether),
string_to_list(ABack,Backtogether),
string_to_list(ABack,Backtogether),
writeln(ABack).</lang>
writeln(ABack).</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,076: Line 3,076:
this can be accomplished in a few lines in the top level:
this can be accomplished in a few lines in the top level:


<lang prolog>
<syntaxhighlight lang="prolog">
?- split_string("Hello,How,Are,You,Today", ",", "", Split),
?- split_string("Hello,How,Are,You,Today", ",", "", Split),
| atomics_to_string(Split, ".", PeriodSeparated),
| atomics_to_string(Split, ".", PeriodSeparated),
| writeln(PeriodSeparated).
| writeln(PeriodSeparated).
Hello.How.Are.You.Today
Hello.How.Are.You.Today
</syntaxhighlight>
</lang>


=={{header|Python}}==
=={{header|Python}}==
{{works with|Python|2.5}}{{works with|Python|3.0}}
{{works with|Python|2.5}}{{works with|Python|3.0}}


<lang python>text = "Hello,How,Are,You,Today"
<syntaxhighlight lang="python">text = "Hello,How,Are,You,Today"
tokens = text.split(',')
tokens = text.split(',')
print ('.'.join(tokens))</lang>
print ('.'.join(tokens))</syntaxhighlight>


Or if interpretation of the task description means you don't need to keep an intermediate array:
Or if interpretation of the task description means you don't need to keep an intermediate array:
<lang python>print ('.'.join('Hello,How,Are,You,Today'.split(',')))</lang>
<syntaxhighlight lang="python">print ('.'.join('Hello,How,Are,You,Today'.split(',')))</syntaxhighlight>


=={{header|Q}}==
=={{header|Q}}==
<lang Q>words: "," vs "Hello,How,Are,You,Today"
<syntaxhighlight lang="q">words: "," vs "Hello,How,Are,You,Today"
"." sv words</lang>
"." sv words</syntaxhighlight>


{{out}}
{{out}}
Line 3,102: Line 3,102:
=={{header|QB64}}==
=={{header|QB64}}==
''CBTJD'': 2020/03/12
''CBTJD'': 2020/03/12
<lang vb>a$ = "Hello,How,Are,You,Today" ' | Initialize original string.
<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.
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.
IF MID$(a$, na, 1) = "," THEN nc = nc + 1 ' | For each comma, increment nc.
Line 3,120: Line 3,120:
PRINT LEFT$(tf$, LEN(tf$) - 1) ' | Print all but the last period of tf$.
PRINT LEFT$(tf$, LEN(tf$) - 1) ' | Print all but the last period of tf$.
END ' | Program end.
END ' | Program end.
</syntaxhighlight>
</lang>


'''Alternative method using word$ function:'''
'''Alternative method using word$ function:'''
----
----
''CBTJD'': 2020/03/12
''CBTJD'': 2020/03/12
<lang vb>a$ = "Hello,How,Are,You,Today" ' | Initialize original string.
<syntaxhighlight lang="vb">a$ = "Hello,How,Are,You,Today" ' | Initialize original string.
DIM t$(LEN(a$) / 2) ' | Create an overestimated sized array.
DIM t$(LEN(a$) / 2) ' | Create an overestimated sized array.
FOR nd = 1 TO LEN(a$) ' | Start loop to find each comma.
FOR nd = 1 TO LEN(a$) ' | Start loop to find each comma.
Line 3,153: Line 3,153:
DONE: ' | Label for bail destination of word count error check.
DONE: ' | Label for bail destination of word count error check.
END FUNCTION ' | End of function.
END FUNCTION ' | End of function.
</syntaxhighlight>
</lang>


=={{header|Quackery}}==
=={{header|Quackery}}==


<lang Quackery> [ [] [] rot
<syntaxhighlight lang="quackery"> [ [] [] rot
witheach
witheach
[ dup char , = iff
[ dup char , = iff
Line 3,166: Line 3,166:
[ witheach [ echo$ say "." ] ] is display ( [ --> )
[ witheach [ echo$ say "." ] ] is display ( [ --> )
$ "Hello,How,Are,You,Today" tokenise display</lang>
$ "Hello,How,Are,You,Today" tokenise display</syntaxhighlight>


{{Out}}
{{Out}}
Line 3,173: Line 3,173:


=={{header|R}}==
=={{header|R}}==
<lang R>text <- "Hello,How,Are,You,Today"
<syntaxhighlight lang="r">text <- "Hello,How,Are,You,Today"
junk <- strsplit(text, split=",")
junk <- strsplit(text, split=",")
print(paste(unlist(junk), collapse="."))</lang>
print(paste(unlist(junk), collapse="."))</syntaxhighlight>


or the one liner
or the one liner


<lang R>paste(unlist(strsplit(text, split=",")), collapse=".")</lang>
<syntaxhighlight lang="r">paste(unlist(strsplit(text, split=",")), collapse=".")</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==


<lang racket>
<syntaxhighlight lang="racket">
#lang racket
#lang racket
(string-join (string-split "Hello,How,Are,You,Today" ",") ".")
(string-join (string-split "Hello,How,Are,You,Today" ",") ".")
;; -> "Hello.How.Are.You.Today"
;; -> "Hello.How.Are.You.Today"
</syntaxhighlight>
</lang>


=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
{{works with|Rakudo|#22 "Thousand Oaks"}}
{{works with|Rakudo|#22 "Thousand Oaks"}}
<lang perl6>'Hello,How,Are,You,Today'.split(',').join('.').say;</lang>
<syntaxhighlight lang="raku" line>'Hello,How,Are,You,Today'.split(',').join('.').say;</syntaxhighlight>


Or with function calls:
Or with function calls:


<lang perl6>say join '.', split ',', 'Hello,How,Are,You,Today';</lang>
<syntaxhighlight lang="raku" line>say join '.', split ',', 'Hello,How,Are,You,Today';</syntaxhighlight>


=={{header|Raven}}==
=={{header|Raven}}==
<lang raven>'Hello,How,Are,You,Today' ',' split '.' join print</lang>
<syntaxhighlight lang="raven">'Hello,How,Are,You,Today' ',' split '.' join print</syntaxhighlight>


=={{header|REBOL}}==
=={{header|REBOL}}==
<lang REBOL>print ["Original:" original: "Hello,How,Are,You,Today"]
<syntaxhighlight lang="rebol">print ["Original:" original: "Hello,How,Are,You,Today"]
tokens: parse original ","
tokens: parse original ","
dotted: "" repeat i tokens [append dotted rejoin [i "."]]
dotted: "" repeat i tokens [append dotted rejoin [i "."]]
print ["Dotted: " dotted]</lang>
print ["Dotted: " dotted]</syntaxhighlight>


{{out}}
{{out}}
Line 3,214: Line 3,214:


=={{header|Red}}==
=={{header|Red}}==
<lang Red>str: "Hello,How,Are,You,Today"
<syntaxhighlight lang="red">str: "Hello,How,Are,You,Today"
>> tokens: split str ","
>> tokens: split str ","
>> probe tokens
>> probe tokens
Line 3,221: Line 3,221:
>> periods: replace/all form tokens " " "." ;The word FORM converts the list series to a string removing quotes.
>> 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
>> print periods ;then REPLACE/ALL spaces with period
Hello.How.Are.You.Today</lang>
Hello.How.Are.You.Today</syntaxhighlight>


=={{header|Retro}}==
=={{header|Retro}}==
<syntaxhighlight lang="retro">{{
<lang Retro>{{
: char ( -$ ) " " ;
: char ( -$ ) " " ;
: tokenize ( $-$$ )
: tokenize ( $-$$ )
Line 3,236: Line 3,236:
[ tokenize action dup 1 <> ] while drop
[ tokenize action dup 1 <> ] while drop
^buffer'get drop ;
^buffer'get drop ;
}}</lang>
}}</syntaxhighlight>


This will suffice to split a string into an array of substrings. It is used like this:
This will suffice to split a string into an array of substrings. It is used like this:


<lang Retro>create strings 100 allot
<syntaxhighlight lang="retro">create strings 100 allot
"Hello,How,Are,You,Today" ', strings split</lang>
"Hello,How,Are,You,Today" ', strings split</syntaxhighlight>


Since the buffer' vocabulary creates a zero-terminated buffer, we can display it using the each@ combinator and a simple quote:
Since the buffer' vocabulary creates a zero-terminated buffer, we can display it using the each@ combinator and a simple quote:


<lang Retro>strings [ @ "%s." puts ] ^types'STRING each@</lang>
<syntaxhighlight lang="retro">strings [ @ "%s." puts ] ^types'STRING each@</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
===version 1===
===version 1===
This REXX version doesn't append a period to the last word in the list.
This REXX version doesn't append a period to the last word in the list.
<lang rexx>/*REXX program separates a string of comma─delimited words, and echoes them ──► terminal*/
<syntaxhighlight lang="rexx">/*REXX program separates a string of comma─delimited words, and echoes them ──► terminal*/
original = 'Hello,How,Are,You,Today' /*some words separated by commas (,). */
original = 'Hello,How,Are,You,Today' /*some words separated by commas (,). */
say 'The input string:' original /*display original string ──► terminal.*/
say 'The input string:' original /*display original string ──► terminal.*/
Line 3,262: Line 3,262:
say @.j || left(., j\==#) /*maybe append a period (.) to a word. */
say @.j || left(., j\==#) /*maybe append a period (.) to a word. */
end /*j*/ /* [↑] don't append a period if last. */
end /*j*/ /* [↑] don't append a period if last. */
say center(' End─of─list ', 40, "═") /*display a (EOL) trailer for the list.*/</lang>
say center(' End─of─list ', 40, "═") /*display a (EOL) trailer for the list.*/</syntaxhighlight>
{{out|output|text=&nbsp; when using the internal default input:}}
{{out|output|text=&nbsp; when using the internal default input:}}
<pre>
<pre>
Line 3,280: Line 3,280:


Hello,Betty Sue,How,Are,You,Today
Hello,Betty Sue,How,Are,You,Today
<lang rexx>/*REXX program to separate a string of comma-delimited words and echo */
<syntaxhighlight lang="rexx">/*REXX program to separate a string of comma-delimited words and echo */
sss='Hello,How,Are,You,Today'
sss='Hello,How,Are,You,Today'
say 'input string='sss
say 'input string='sss
Line 3,291: Line 3,291:
say word(ss,i)dot
say word(ss,i)dot
End
End
say 'End-of-list.'</lang>
say 'End-of-list.'</syntaxhighlight>
'''output''' is similar to REXX version 1.
'''output''' is similar to REXX version 1.


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
see substr("Hello,How,Are,You,Today", ",", ".")
see substr("Hello,How,Are,You,Today", ",", ".")
</syntaxhighlight>
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>puts "Hello,How,Are,You,Today".split(',').join('.')</lang>
<syntaxhighlight lang="ruby">puts "Hello,How,Are,You,Today".split(',').join('.')</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>fn main() {
<syntaxhighlight lang="rust">fn main() {
let s = "Hello,How,Are,You,Today";
let s = "Hello,How,Are,You,Today";
let tokens: Vec<&str> = s.split(",").collect();
let tokens: Vec<&str> = s.split(",").collect();
println!("{}", tokens.join("."));
println!("{}", tokens.join("."));
}</lang>
}</syntaxhighlight>


=={{header|S-lang}}==
=={{header|S-lang}}==
<lang S-lang>variable a = strchop("Hello,How,Are,You,Today", ',', 0);
<syntaxhighlight lang="s-lang">variable a = strchop("Hello,How,Are,You,Today", ',', 0);
print(strjoin(a, "."));</lang>
print(strjoin(a, "."));</syntaxhighlight>


{{out}}
{{out}}
Line 3,317: Line 3,317:


=={{header|Scala}}==
=={{header|Scala}}==
<lang scala>println("Hello,How,Are,You,Today" split "," mkString ".")</lang>
<syntaxhighlight lang="scala">println("Hello,How,Are,You,Today" split "," mkString ".")</syntaxhighlight>


=={{header|Scheme}}==
=={{header|Scheme}}==
{{works with|Guile}}
{{works with|Guile}}
<lang scheme>(use-modules (ice-9 regex))
<syntaxhighlight lang="scheme">(use-modules (ice-9 regex))
(define s "Hello,How,Are,You,Today")
(define s "Hello,How,Are,You,Today")
(define words (map match:substring (list-matches "[^,]+" s)))
(define words (map match:substring (list-matches "[^,]+" s)))
Line 3,328: Line 3,328:
(display (list-ref words n))
(display (list-ref words n))
(if (< n (- (length words) 1))
(if (< n (- (length words) 1))
(display ".")))</lang>
(display ".")))</syntaxhighlight>


(with SRFI 13)
(with SRFI 13)
<lang scheme>(define s "Hello,How,Are,You,Today")
<syntaxhighlight lang="scheme">(define s "Hello,How,Are,You,Today")
(define words (string-tokenize s (char-set-complement (char-set #\,))))
(define words (string-tokenize s (char-set-complement (char-set #\,))))
(define t (string-join words "."))</lang>
(define t (string-join words "."))</syntaxhighlight>


{{works with|Gauche Scheme}}
{{works with|Gauche Scheme}}
<lang Scheme>(print
<syntaxhighlight lang="scheme">(print
(string-join
(string-join
(string-split "Hello,How,Are,You,Today" #\,)
(string-split "Hello,How,Are,You,Today" #\,)
".")) </lang>
".")) </syntaxhighlight>
{{output}}
{{output}}
<pre>
<pre>
Line 3,346: Line 3,346:


=={{header|Seed7}}==
=={{header|Seed7}}==
<lang seed7>var array string: tokens is 0 times "";
<syntaxhighlight lang="seed7">var array string: tokens is 0 times "";


tokens := split("Hello,How,Are,You,Today", ",");</lang>
tokens := split("Hello,How,Are,You,Today", ",");</syntaxhighlight>


=={{header|Self}}==
=={{header|Self}}==
<lang self>| s = 'Hello,How,Are,You,Today' |
<syntaxhighlight lang="self">| s = 'Hello,How,Are,You,Today' |
((s splitOn: ',') joinUsing: '.') printLine.
((s splitOn: ',') joinUsing: '.') printLine.
</syntaxhighlight>
</lang>


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>'Hello,How,Are,You,Today'.split(',').join('.').say;</lang>
<syntaxhighlight lang="ruby">'Hello,How,Are,You,Today'.split(',').join('.').say;</syntaxhighlight>
=={{header|Simula}}==
=={{header|Simula}}==
<lang simula>BEGIN
<syntaxhighlight lang="simula">BEGIN


CLASS TEXTARRAY(N); INTEGER N;
CLASS TEXTARRAY(N); INTEGER N;
Line 3,408: Line 3,408:


END.
END.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>HELLO.HOW.ARE.YOU.TODAY.</pre>
<pre>HELLO.HOW.ARE.YOU.TODAY.</pre>


=={{header|Slate}}==
=={{header|Slate}}==
<lang slate>('Hello,How,Are,You,Today' splitWith: $,) join &separator: '.'.</lang>
<syntaxhighlight lang="slate">('Hello,How,Are,You,Today' splitWith: $,) join &separator: '.'.</syntaxhighlight>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
<lang smalltalk>|array |
<syntaxhighlight lang="smalltalk">|array |
array := 'Hello,How,Are,You,Today' subStrings: $,.
array := 'Hello,How,Are,You,Today' subStrings: $,.
array fold: [:concatenation :string | concatenation, '.', string ]</lang>
array fold: [:concatenation :string | concatenation, '.', string ]</syntaxhighlight>


Some implementations also have a ''join:'' convenience method that allows the following shorter solution:
Some implementations also have a ''join:'' convenience method that allows the following shorter solution:


<lang smalltalk>('Hello,How,Are,You,Today' subStrings: $,) join: '.'</lang>
<syntaxhighlight lang="smalltalk">('Hello,How,Are,You,Today' subStrings: $,) join: '.'</syntaxhighlight>


The solution displaying a trailing period would be:
The solution displaying a trailing period would be:


<lang smalltalk>|array |
<syntaxhighlight lang="smalltalk">|array |
array := 'Hello,How,Are,You,Today' subStrings: $,.
array := 'Hello,How,Are,You,Today' subStrings: $,.
array inject: '' into: [:concatenation :string | concatenation, string, '.' ]</lang>
array inject: '' into: [:concatenation :string | concatenation, string, '.' ]</syntaxhighlight>


=={{header|SNOBOL4}}==
=={{header|SNOBOL4}}==
Line 3,434: Line 3,434:
For this task, it's convenient to define Perl-style split( ) and join( ) functions.
For this task, it's convenient to define Perl-style split( ) and join( ) functions.


<lang SNOBOL4> define('split(chs,str)i,j,t,w2') :(split_end)
<syntaxhighlight lang="snobol4"> define('split(chs,str)i,j,t,w2') :(split_end)
split t = table()
split t = table()
sp1 str pos(0) (break(chs) | rem) $ t<i = i + 1>
sp1 str pos(0) (break(chs) | rem) $ t<i = i + 1>
Line 3,450: Line 3,450:
* # Test and display
* # Test and display
output = join('.',split(',','Hello,How,Are,You,Today'))
output = join('.',split(',','Hello,How,Are,You,Today'))
end</lang>
end</syntaxhighlight>


{{out}}
{{out}}
Line 3,458: Line 3,458:


=={{header|Standard ML}}==
=={{header|Standard ML}}==
<lang sml>val splitter = String.tokens (fn c => c = #",");
<syntaxhighlight lang="sml">val splitter = String.tokens (fn c => c = #",");
val main = (String.concatWith ".") o splitter;</lang>
val main = (String.concatWith ".") o splitter;</syntaxhighlight>


Test:
Test:


<lang sml>- main "Hello,How,Are,You,Today"
<syntaxhighlight lang="sml">- main "Hello,How,Are,You,Today"
val it = "Hello.How.Are.You.Today" : string</lang>
val it = "Hello.How.Are.You.Today" : string</syntaxhighlight>


=={{header|Swift}}==
=={{header|Swift}}==


{{works with|Swift|3.x}}
{{works with|Swift|3.x}}
<lang swift>let text = "Hello,How,Are,You,Today"
<syntaxhighlight lang="swift">let text = "Hello,How,Are,You,Today"
let tokens = text.components(separatedBy: ",") // for single or multi-character separator
let tokens = text.components(separatedBy: ",") // for single or multi-character separator
print(tokens)
print(tokens)
let result = tokens.joined(separator: ".")
let result = tokens.joined(separator: ".")
print(result)</lang>
print(result)</syntaxhighlight>


{{works with|Swift|2.x}}
{{works with|Swift|2.x}}
<lang swift>let text = "Hello,How,Are,You,Today"
<syntaxhighlight lang="swift">let text = "Hello,How,Are,You,Today"
let tokens = text.characters.split(",").map{String($0)} // for single-character separator
let tokens = text.characters.split(",").map{String($0)} // for single-character separator
print(tokens)
print(tokens)
let result = tokens.joinWithSeparator(".")
let result = tokens.joinWithSeparator(".")
print(result)</lang>
print(result)</syntaxhighlight>


{{works with|Swift|1.x}}
{{works with|Swift|1.x}}
<lang swift>let text = "Hello,How,Are,You,Today"
<syntaxhighlight lang="swift">let text = "Hello,How,Are,You,Today"
let tokens = split(text, { $0 == "," }) // for single-character separator
let tokens = split(text, { $0 == "," }) // for single-character separator
println(tokens)
println(tokens)
let result = ".".join(tokens)
let result = ".".join(tokens)
println(result)</lang>
println(result)</syntaxhighlight>


For multi-character separators:<lang swift>import Foundation
For multi-character separators:<syntaxhighlight lang="swift">import Foundation


let text = "Hello,How,Are,You,Today"
let text = "Hello,How,Are,You,Today"
let tokens = text.componentsSeparatedByString(",")
let tokens = text.componentsSeparatedByString(",")
print(tokens)</lang>
print(tokens)</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
Generating a list form a string by splitting on a comma:
Generating a list form a string by splitting on a comma:
<lang tcl>split $string ","</lang>
<syntaxhighlight lang="tcl">split $string ","</syntaxhighlight>


Joining the elements of a list by a period:
Joining the elements of a list by a period:
<lang tcl>join $list "."</lang>
<syntaxhighlight lang="tcl">join $list "."</syntaxhighlight>


Thus the whole thing would look like this:
Thus the whole thing would look like this:
<lang tcl>puts [join [split "Hello,How,Are,You,Today" ","] "."]</lang>
<syntaxhighlight lang="tcl">puts [join [split "Hello,How,Are,You,Today" ","] "."]</syntaxhighlight>


If you'd like to retain the list in a variable with the name "words", it would only be marginally more complex:
If you'd like to retain the list in a variable with the name "words", it would only be marginally more complex:
<lang tcl>puts [join [set words [split "Hello,How,Are,You,Today" ","]] "."]</lang>
<syntaxhighlight lang="tcl">puts [join [set words [split "Hello,How,Are,You,Today" ","]] "."]</syntaxhighlight>


(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.)
(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 3,513: Line 3,513:
<code>tr</code> knows nothing about arrays, so this solution only changes each comma to a period.
<code>tr</code> knows nothing about arrays, so this solution only changes each comma to a period.


<lang bash>echo 'Hello,How,Are,You,Today' | tr ',' '.'</lang>
<syntaxhighlight lang="bash">echo 'Hello,How,Are,You,Today' | tr ',' '.'</syntaxhighlight>


=={{header|TUSCRIPT}}==
=={{header|TUSCRIPT}}==
<lang tuscript>
<syntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
$$ MODE TUSCRIPT
SET string="Hello,How,Are,You,Today"
SET string="Hello,How,Are,You,Today"
SET string=SPLIT (string,":,:")
SET string=SPLIT (string,":,:")
SET string=JOIN (string,".")
SET string=JOIN (string,".")
</syntaxhighlight>
</lang>


=={{header|TXR}}==
=={{header|TXR}}==
Line 3,528: Line 3,528:
sequences of non-commas.
sequences of non-commas.


<lang txr>@(next :list "Hello,How,Are,You,Today")
<syntaxhighlight lang="txr">@(next :list "Hello,How,Are,You,Today")
@(coll)@{token /[^,]+/}@(end)
@(coll)@{token /[^,]+/}@(end)
@(output)
@(output)
@(rep)@token.@(last)@token@(end)
@(rep)@token.@(last)@token@(end)
@(end)</lang>
@(end)</syntaxhighlight>


Different approach. Collect tokens, each of
Different approach. Collect tokens, each of
Line 3,538: Line 3,538:
before a comma, or else extends to the end of the line.
before a comma, or else extends to the end of the line.


<lang txr>@(next :list "Hello,How,Are,You,Today")
<syntaxhighlight lang="txr">@(next :list "Hello,How,Are,You,Today")
@(coll)@(maybe)@token,@(or)@token@(end)@(end)
@(coll)@(maybe)@token,@(or)@token@(end)@(end)
@(output)
@(output)
@(rep)@token.@(last)@token@(end)
@(rep)@token.@(last)@token@(end)
@(end)</lang>
@(end)</syntaxhighlight>


Using TXR Lisp:
Using TXR Lisp:


<lang bash>txr -p '(cat-str (split-str "Hello,How,Are,You,Today" ",") ".")'
<syntaxhighlight lang="bash">txr -p '(cat-str (split-str "Hello,How,Are,You,Today" ",") ".")'
Hello.How.Are.You.Today</lang>
Hello.How.Are.You.Today</syntaxhighlight>


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
{{works with|Bourne Shell}}
{{works with|Bourne Shell}}
<lang bash>string='Hello,How,Are,You,Today'
<syntaxhighlight lang="bash">string='Hello,How,Are,You,Today'


(IFS=,
(IFS=,
printf '%s.' $string
printf '%s.' $string
echo)</lang>
echo)</syntaxhighlight>


----
----
{{works with|Bourne Again SHell}}
{{works with|Bourne Again SHell}}
{{works with|Public Domain Korn SHell|5.2.14}}
{{works with|Public Domain Korn SHell|5.2.14}}
<lang bash>#! /bin/bash
<syntaxhighlight lang="bash">#! /bin/bash
stripchar-l ()
stripchar-l ()
#removes the specified character from the left side of the string
#removes the specified character from the left side of the string
Line 3,617: Line 3,617:
join "$( split "$list" "$input_delimiter" )" \
join "$( split "$list" "$input_delimiter" )" \
"$contains_a_space" "$output_delimiter";
"$contains_a_space" "$output_delimiter";
}</lang>
}</syntaxhighlight>


''Example''
''Example''


<lang bash> strtokenize "Hello,How,Are,You,Today" "," "."
<syntaxhighlight lang="bash"> strtokenize "Hello,How,Are,You,Today" "," "."
Hello.How.Are.You.Today </lang>
Hello.How.Are.You.Today </syntaxhighlight>


----
----
Line 3,630: Line 3,630:
{{works with|ksh93}}
{{works with|ksh93}}
{{works with|zsh}}
{{works with|zsh}}
<syntaxhighlight lang="sh">
<lang sh>
string1="Hello,How,Are,You,Today"
string1="Hello,How,Are,You,Today"
elements_quantity=$(echo $string1|tr "," "\n"|wc -l)
elements_quantity=$(echo $string1|tr "," "\n"|wc -l)
Line 3,643: Line 3,643:


# or to cheat
# or to cheat
echo "Hello,How,Are,You,Today"|tr "," "."</lang>
echo "Hello,How,Are,You,Today"|tr "," "."</syntaxhighlight>


=={{header|UnixPipes}}==
=={{header|UnixPipes}}==
{{works with|Bourne Shell}}
{{works with|Bourne Shell}}
<lang bash>token() {
<syntaxhighlight lang="bash">token() {
(IFS=, read -r A B; echo "$A".; test -n "$B" && (echo "$B" | token))
(IFS=, read -r A B; echo "$A".; test -n "$B" && (echo "$B" | token))
}
}


echo "Hello,How,Are,You" | token</lang>
echo "Hello,How,Are,You" | token</syntaxhighlight>


=={{header|Ursa}}==
=={{header|Ursa}}==
<lang ursa>decl string text
<syntaxhighlight lang="ursa">decl string text
set text "Hello,How,Are,You,Today"
set text "Hello,How,Are,You,Today"
decl string<> tokens
decl string<> tokens
Line 3,661: Line 3,661:
out tokens<i> "." console
out tokens<i> "." console
end for
end for
out endl console</lang>
out endl console</syntaxhighlight>


=={{header|Ursala}}==
=={{header|Ursala}}==
Line 3,669: Line 3,669:
second order function parameterized by the delimiter. Character
second order function parameterized by the delimiter. Character
literals are preceded by a backquote.
literals are preceded by a backquote.
<lang Ursala>#import std
<syntaxhighlight lang="ursala">#import std


token_list = sep`, 'Hello,How,Are,You,Today'
token_list = sep`, 'Hello,How,Are,You,Today'
Line 3,675: Line 3,675:
#cast %s
#cast %s


main = mat`. token_list</lang>
main = mat`. token_list</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,682: Line 3,682:


=={{header|Vala}}==
=={{header|Vala}}==
<lang Vala>void main() {
<syntaxhighlight lang="vala">void main() {
string s = "Hello,How,Are,You,Today";
string s = "Hello,How,Are,You,Today";
print(@"$(string.joinv(".", s.split(",")))");
print(@"$(string.joinv(".", s.split(",")))");
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Hello.How.Are.You.Today</pre>
<pre>Hello.How.Are.You.Today</pre>


=={{header|VBA}}==
=={{header|VBA}}==
<lang vb>Sub Main()
<syntaxhighlight lang="vb">Sub Main()
Dim temp() As String
Dim temp() As String
temp = Tokenize("Hello,How,Are,You,Today", ",")
temp = Tokenize("Hello,How,Are,You,Today", ",")
Line 3,702: Line 3,702:
Private Sub Display(arr() As String, sep As String)
Private Sub Display(arr() As String, sep As String)
Debug.Print Join(arr, sep)
Debug.Print Join(arr, sep)
End Sub</lang>
End Sub</syntaxhighlight>
{{Out}}
{{Out}}
<pre>Hello How Are You Today</pre>
<pre>Hello How Are You Today</pre>


=={{header|VBScript}}==
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
s = "Hello,How,Are,You,Today"
s = "Hello,How,Are,You,Today"
WScript.StdOut.Write Join(Split(s,","),".")
WScript.StdOut.Write Join(Split(s,","),".")
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>Hello.How.Are.You.Today</pre>
<pre>Hello.How.Are.You.Today</pre>
Line 3,720: Line 3,720:
The contents of each text register is then displayed to user, separated by a period.
The contents of each text register is then displayed to user, separated by a period.


<lang vedit>Buf_Switch(Buf_Free)
<syntaxhighlight lang="vedit">Buf_Switch(Buf_Free)
Ins_Text("Hello,How,Are,You,Today")
Ins_Text("Hello,How,Are,You,Today")


Line 3,739: Line 3,739:
}
}


Buf_Quit(OK)</lang>
Buf_Quit(OK)</syntaxhighlight>


=={{header|Vlang}}==
=={{header|Vlang}}==
<lang go>// Tokenize a string, in V
<syntaxhighlight lang="go">// Tokenize a string, in V
// Tectonics: v run tokenize-a-string.v
// Tectonics: v run tokenize-a-string.v
module main
module main
Line 3,749: Line 3,749:
pub fn main() {
pub fn main() {
println("Hello,How,Are,You,Today".split(',').join('.'))
println("Hello,How,Are,You,Today".split(',').join('.'))
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>prompt$ v run rosetta/tokenize-a-string.v
<pre>prompt$ v run rosetta/tokenize-a-string.v
Line 3,756: Line 3,756:
=={{header|WinBatch}}==
=={{header|WinBatch}}==


<lang WinBatch>text = 'Hello,How,Are,You,Today'
<syntaxhighlight lang="winbatch">text = 'Hello,How,Are,You,Today'
result = ''
result = ''
BoxOpen('WinBatch Tokenizing Example', '')
BoxOpen('WinBatch Tokenizing Example', '')
Line 3,764: Line 3,764:
next
next
display(10, 'End of Program', 'Dialog and program will close momentarily.')
display(10, 'End of Program', 'Dialog and program will close momentarily.')
BoxShut()</lang>
BoxShut()</syntaxhighlight>


{{out}}
{{out}}
Line 3,770: Line 3,770:


=={{header|Wortel}}==
=={{header|Wortel}}==
<lang wortel>@join "." @split "," "Hello,How,Are,You,Today"</lang>
<syntaxhighlight lang="wortel">@join "." @split "," "Hello,How,Are,You,Today"</syntaxhighlight>
Returns
Returns
<pre>"Hello.How.Are.You.Today"</pre>
<pre>"Hello.How.Are.You.Today"</pre>


=={{header|Wren}}==
=={{header|Wren}}==
<lang ecmascript>var s = "Hello,How,Are,You,Today"
<syntaxhighlight lang="ecmascript">var s = "Hello,How,Are,You,Today"
var t = s.split(",").join(".") + "."
var t = s.split(",").join(".") + "."
System.print(t)</lang>
System.print(t)</syntaxhighlight>


{{out}}
{{out}}
Line 3,785: Line 3,785:


=={{header|XPath 2.0}}==
=={{header|XPath 2.0}}==
<lang XPath>string-join(tokenize("Hello,How,Are,You,Today", ","), ".")</lang>
<syntaxhighlight lang="xpath">string-join(tokenize("Hello,How,Are,You,Today", ","), ".")</syntaxhighlight>


{{out}}
{{out}}
Line 3,791: Line 3,791:


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>string 0;
<syntaxhighlight lang="xpl0">string 0;
include c:\cxpl\codes;
include c:\cxpl\codes;
int I, J, K, Char;
int I, J, K, Char;
Line 3,810: Line 3,810:
for K:= 4 downto 0 do [Text(0, addr Array(K,0)); ChOut(0, ^.)];
for K:= 4 downto 0 do [Text(0, addr Array(K,0)); ChOut(0, ^.)];
CrLf(0);
CrLf(0);
]</lang>
]</syntaxhighlight>


The 'addr' operator is used to fetch the 32-bit address of Array rather
The 'addr' operator is used to fetch the 32-bit address of Array rather
Line 3,821: Line 3,821:


=={{header|Yabasic}}==
=={{header|Yabasic}}==
<lang Yabasic>dim s$(1)
<syntaxhighlight lang="yabasic">dim s$(1)


n = token("Hello. How are you today?", s$(), ".? ")
n = token("Hello. How are you today?", s$(), ".? ")
Line 3,829: Line 3,829:
if i < n print ".";
if i < n print ".";
next
next
print</lang>
print</syntaxhighlight>


=={{header|zkl}}==
=={{header|zkl}}==
<lang zkl>"Hello,How,Are,You,Today".split(",").concat(".").println();
<syntaxhighlight lang="zkl">"Hello,How,Are,You,Today".split(",").concat(".").println();
Hello.How.Are.You.Today</lang>
Hello.How.Are.You.Today</syntaxhighlight>


=={{header|Zoea}}==
=={{header|Zoea}}==
<syntaxhighlight lang="zoea">
<lang Zoea>
program: tokenize_a_string
program: tokenize_a_string
input: "Hello,How,Are,You,Today"
input: "Hello,How,Are,You,Today"
output: "Hello.How.Are.You.Today"
output: "Hello.How.Are.You.Today"
</syntaxhighlight>
</lang>


=={{header|Zoea Visual}}==
=={{header|Zoea Visual}}==
Line 3,846: Line 3,846:


=={{header|Zsh}}==
=={{header|Zsh}}==
<lang zsh>str='Hello,How,Are,You,Today'
<syntaxhighlight lang="zsh">str='Hello,How,Are,You,Today'
tokens=(${(s:,:)str})
tokens=(${(s:,:)str})
print ${(j:.:)tokens}</lang>
print ${(j:.:)tokens}</syntaxhighlight>


Or, using SH_SPLIT_WORD:
Or, using SH_SPLIT_WORD:


<lang zsh>str='Hello,How,Are,You,Today'
<syntaxhighlight lang="zsh">str='Hello,How,Are,You,Today'
IFS=, echo ${(j:.:)${=str}}</lang>
IFS=, echo ${(j:.:)${=str}}</syntaxhighlight>


{{omit from|PARI/GP|No real capacity for string manipulation}}
{{omit from|PARI/GP|No real capacity for string manipulation}}