Tokenize a string: Difference between revisions
Content deleted Content added
m →[[Java]]: Use Java header instead |
m Switched to header template |
||
Line 2: | Line 2: | ||
Separate the string "Hello,How,Are,You,Today" by commas into an array so that each index of the array stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. |
Separate the string "Hello,How,Are,You,Today" by commas into an array so that each index of the array stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period. |
||
== |
=={{header|Ada}}== |
||
[[Category:Ada]] |
|||
with Ada.Strings.Fixed; use Ada.Strings.Fixed; |
with Ada.Strings.Fixed; use Ada.Strings.Fixed; |
||
with Ada.Text_Io; use Ada.Text_Io; |
with Ada.Text_Io; use Ada.Text_Io; |
||
Line 24: | Line 22: | ||
end Parse_Commas; |
end Parse_Commas; |
||
== |
=={{header|C}}== |
||
'''Standard:''' ANSI C |
'''Standard:''' ANSI C |
||
Line 59: | Line 57: | ||
</pre> |
</pre> |
||
== |
=={{header|C sharp|C#}}== |
||
[[Category:C#]] |
|||
string str = "Hello,How,Are,You,Today"; |
string str = "Hello,How,Are,You,Today"; |
||
Line 133: | Line 130: | ||
} |
} |
||
== |
=={{header|E}}== |
||
[[Category:E]] |
|||
".".rjoin("Hello,How,Are,You,Today".split(",")) |
".".rjoin("Hello,How,Are,You,Today".split(",")) |
||
== |
=={{header|Forth}}== |
||
[[Category: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. |
||
Line 162: | Line 155: | ||
s" Hello,How,Are,You,Today" s" ," split .tokens \ Hello.How.Are.You.Today |
s" Hello,How,Are,You,Today" s" ," split .tokens \ Hello.How.Are.You.Today |
||
== |
=={{header|Groovy}}== |
||
[[Category:Groovy]] |
|||
println 'Hello,How,Are,You,Today'.split(',').join('.') |
println 'Hello,How,Are,You,Today'.split(',').join('.') |
||
Line 187: | Line 178: | ||
} |
} |
||
== |
=={{header|JavaScript}}== |
||
[[Category:JavaScript]] |
|||
'''Interpreter:''' Firefox 2.0 |
'''Interpreter:''' Firefox 2.0 |
||
alert( "Hello,How,Are,You,Today".split(",").join(".") ); |
alert( "Hello,How,Are,You,Today".split(",").join(".") ); |
||
== |
=={{header|MAXScript}}== |
||
[[Category:MAXScript]] |
|||
output = "" |
output = "" |
||
for word in (filterString "Hello,How,Are,You,Today" ",") do |
for word in (filterString "Hello,How,Are,You,Today" ",") do |
||
Line 202: | Line 191: | ||
format "%\n" output |
format "%\n" output |
||
== |
=={{header|Perl}}== |
||
[[Category:Perl]] |
|||
'''Interpreter:''' [[Perl]] any 5.X |
'''Interpreter:''' [[Perl]] any 5.X |
||
Line 220: | Line 208: | ||
print $_.'.' for (@words); |
print $_.'.' for (@words); |
||
== |
=={{header|PHP}}== |
||
[[Category:PHP]] |
|||
'''Interpreter:''' [[PHP]] any 5.x |
'''Interpreter:''' [[PHP]] any 5.x |
||
Line 230: | Line 217: | ||
?> |
?> |
||
== |
=={{header|Pop11}}== |
||
[[Category:Pop11]] |
|||
Natural solution in Pop11 uses lists: |
Natural solution in Pop11 uses lists: |
||
Line 274: | Line 259: | ||
so the convertion to vector is purely to satisfy task formulation. |
so the convertion to vector is purely to satisfy task formulation. |
||
== |
=={{header|Python}}== |
||
[[Category:Python]] |
|||
'''Interpreter:''' Python 2.5 |
'''Interpreter:''' Python 2.5 |
||
Line 291: | Line 275: | ||
print "\n".join(tokens) |
print "\n".join(tokens) |
||
== |
=={{header|Raven}}== |
||
[[Category:Raven]] |
|||
'Hello,How,Are,You,Today' ',' split '.' join print |
'Hello,How,Are,You,Today' ',' split '.' join print |
||
== |
=={{header|Ruby}}== |
||
[[Category:Ruby]] |
|||
string = "Hello,How,Are,You,Today".split(',') |
string = "Hello,How,Are,You,Today".split(',') |
||
string.each do |w| |
string.each do |w| |
||
Line 306: | Line 286: | ||
puts "Hello,How,Are,You,Today".split(',').join('.') |
puts "Hello,How,Are,You,Today".split(',').join('.') |
||
== |
=={{header|Seed7}}== |
||
[[Category:Seed7]] |
|||
var array string: tokens is 0 times ""; |
var array string: tokens is 0 times ""; |
||
tokens := split("Hello,How,Are,You,Today", ","); |
tokens := split("Hello,How,Are,You,Today", ","); |
||
== |
=={{header|Smalltalk}}== |
||
[[Category:Smalltalk]] |
|||
|array | |
|array | |
||
array := ('Hello,How,Are,You,Today' findTokens: $,) asArray. |
array := ('Hello,How,Are,You,Today' findTokens: $,) asArray. |
||
Line 323: | Line 299: | ||
[:concatenation :string | concatenation , string , '.']) |
[:concatenation :string | concatenation , string , '.']) |
||
== |
=={{header|Standard ML}}== |
||
[[Category:Standard ML]] |
|||
val splitter = String.tokens (fn c => c = #","); |
val splitter = String.tokens (fn c => c = #","); |
||
val main = (String.concatWith ".") o splitter; |
val main = (String.concatWith ".") o splitter; |
||
Line 334: | Line 308: | ||
<i>val it = "Hello.How.Are.You.Today" : string</i> |
<i>val it = "Hello.How.Are.You.Today" : string</i> |
||
== |
=={{header|Tcl}}== |
||
[[Category:Tcl]] |
|||
Generating a list form a string by splitting on a comma: |
Generating a list form a string by splitting on a comma: |
||