Tokenize a string: Difference between revisions

Add CLU
mNo edit summary
(Add CLU)
Line 1,253:
Using the clojure.string library:
<lang clojure>(clojure.string/join "." (clojure.string/split "Hello,How,Are,You,Today" #","))</lang>
 
=={{header|CLU}}==
<lang clu>% This iterator splits the string on a given character,
% and returns each substring in order.
tokenize = iter (s: string, c: char) yields (string)
while ~string$empty(s) do
next: int := string$indexc(c, s)
if next = 0 then
yield(s)
break
else
yield(string$substr(s, 1, next-1))
s := string$rest(s, next+1)
end
end
end tokenize
 
start_up = proc ()
po: stream := stream$primary_output()
str: string := "Hello,How,Are,You,Today"
for part: string in tokenize(str, ',') do
stream$putl(po, part || ".")
end
end start_up</lang>
{{out}}
<pre>Hello.
How.
Are.
You.
Today.</pre>
 
=={{header|COBOL}}==
2,114

edits