Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1 +1,7 @@
|
|||
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word. Display the words to the 'user', in the simplest manner possible, separated by a period. To simplify, you may display a trailing period.
|
||||
Separate the string "Hello,How,Are,You,Today" by commas into an array (or list) so that each element of it stores a different word.
|
||||
Display the words to the 'user', in the simplest manner possible, separated by a period.
|
||||
To simplify, you may display a trailing period.
|
||||
|
||||
'''''Related tasks:'''''
|
||||
|
||||
* [[Tokenize a string with escaping]]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import std.stdio, std.string;
|
||||
|
||||
void main() {
|
||||
"Hello,How,Are,You,Today".split(",").join(".").writeln();
|
||||
import std.stdio, std.string;
|
||||
|
||||
"Hello,How,Are,You,Today".split(',').join('.').writeln;
|
||||
}
|
||||
|
|
|
|||
2
Task/Tokenize-a-string/Elixir/tokenize-a-string.elixir
Normal file
2
Task/Tokenize-a-string/Elixir/tokenize-a-string.elixir
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
tokens = String.split("Hello,How,Are,You,Today", ",")
|
||||
IO.puts Enum.join(tokens, ".")
|
||||
|
|
@ -1,7 +1,2 @@
|
|||
String toTokenize = "Hello,How,Are,You,Today";
|
||||
|
||||
String words[] = toTokenize.split(",");//splits on one comma, multiple commas yield multiple splits
|
||||
//toTokenize.split(",+") if you want to ignore empty fields
|
||||
for(int i=0; i<words.length; i++) {
|
||||
System.out.print(words[i] + ".");
|
||||
}
|
||||
System.out.println(String.join(".", toTokenize.split(",")));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
String toTokenize = "Hello,How,Are,You,Today";
|
||||
|
||||
StringTokenizer tokenizer = new StringTokenizer(toTokenize, ",");
|
||||
while(tokenizer.hasMoreTokens()) {
|
||||
System.out.print(tokenizer.nextToken() + ".");
|
||||
String words[] = toTokenize.split(",");//splits on one comma, multiple commas yield multiple splits
|
||||
//toTokenize.split(",+") if you want to ignore empty fields
|
||||
for(int i=0; i<words.length; i++) {
|
||||
System.out.print(words[i] + ".");
|
||||
}
|
||||
|
|
|
|||
6
Task/Tokenize-a-string/Java/tokenize-a-string-3.java
Normal file
6
Task/Tokenize-a-string/Java/tokenize-a-string-3.java
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
String toTokenize = "Hello,How,Are,You,Today";
|
||||
|
||||
StringTokenizer tokenizer = new StringTokenizer(toTokenize, ",");
|
||||
while(tokenizer.hasMoreTokens()) {
|
||||
System.out.print(tokenizer.nextToken() + ".");
|
||||
}
|
||||
22
Task/Tokenize-a-string/Logtalk/tokenize-a-string.logtalk
Normal file
22
Task/Tokenize-a-string/Logtalk/tokenize-a-string.logtalk
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
:- object(spliting).
|
||||
|
||||
:- public(convert/2).
|
||||
:- mode(convert(+atom, -atom), one).
|
||||
|
||||
convert(StringIn, StringOut) :-
|
||||
atom_chars(StringIn, CharactersIn),
|
||||
phrase(split(',', Tokens), CharactersIn),
|
||||
phrase(split('.', Tokens), CharactersOut),
|
||||
atom_chars(StringOut, CharactersOut).
|
||||
|
||||
split(Separator, [t([Character| Characters])| Tokens]) -->
|
||||
[Character], {Character \== Separator}, split(Separator, [t(Characters)| Tokens]).
|
||||
split(Separator, [t([])| Tokens]) -->
|
||||
[Separator], split(Separator, Tokens).
|
||||
split(_, [t([])]) -->
|
||||
[].
|
||||
% the look-ahead in the next rule prevents adding a spurious separator at the end
|
||||
split(_, []), [Character] -->
|
||||
[Character].
|
||||
|
||||
:- end_object.
|
||||
14
Task/Tokenize-a-string/MATLAB/tokenize-a-string.m
Normal file
14
Task/Tokenize-a-string/MATLAB/tokenize-a-string.m
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function tokenizeString(string,delimeter)
|
||||
|
||||
tokens = {};
|
||||
|
||||
while not(isempty(string))
|
||||
[tokens{end+1},string] = strtok(string,delimeter);
|
||||
end
|
||||
|
||||
for i = (1:numel(tokens)-1)
|
||||
fprintf([tokens{i} '.'])
|
||||
end
|
||||
|
||||
fprintf([tokens{end} '\n'])
|
||||
end
|
||||
1
Task/Tokenize-a-string/NewLISP/tokenize-a-string.newlisp
Normal file
1
Task/Tokenize-a-string/NewLISP/tokenize-a-string.newlisp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(print (join (parse "Hello,How,Are,You,Today" ",") "."))
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
tok: Proc Options(main);
|
||||
declare s character (100) initial ('Hello,How,Are,You,Today');
|
||||
declare n fixed binary (31);
|
||||
|
||||
|
|
@ -19,3 +20,4 @@ begin;
|
|||
table = table || '.';
|
||||
put skip list (string(table));
|
||||
end;
|
||||
end;
|
||||
|
|
|
|||
1
Task/Tokenize-a-string/Perl/tokenize-a-string-2.pl
Normal file
1
Task/Tokenize-a-string/Perl/tokenize-a-string-2.pl
Normal file
|
|
@ -0,0 +1 @@
|
|||
echo "Hello,How,Are,You,Today" | perl -aplF/,/ -e '$" = "."; $_ = "@F";'
|
||||
10
Task/Tokenize-a-string/Perl/tokenize-a-string-3.pl
Normal file
10
Task/Tokenize-a-string/Perl/tokenize-a-string-3.pl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
BEGIN { $/ = "\n"; $\ = "\n"; }
|
||||
LINE: while (defined($_ = <ARGV>)) {
|
||||
chomp $_;
|
||||
our(@F) = split(/,/, $_, 0);
|
||||
$" = '.';
|
||||
$_ = "@F";
|
||||
}
|
||||
continue {
|
||||
die "-p destination: $!\n" unless print $_;
|
||||
}
|
||||
4
Task/Tokenize-a-string/Prolog/tokenize-a-string-2.pro
Normal file
4
Task/Tokenize-a-string/Prolog/tokenize-a-string-2.pro
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
?- split_string("Hello,How,Are,You,Today", ",", "", Split),
|
||||
| atomics_to_string(Split, ".", PeriodSeparated),
|
||||
| writeln(PeriodSeparated).
|
||||
Hello.How.Are.You.Today
|
||||
4
Task/Tokenize-a-string/Scheme/tokenize-a-string-3.ss
Normal file
4
Task/Tokenize-a-string/Scheme/tokenize-a-string-3.ss
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(print
|
||||
(string-join
|
||||
(string-split "Hello,How,Are,You,Today" #\,)
|
||||
"."))
|
||||
|
|
@ -1 +1,2 @@
|
|||
@(bind result @(cat-str (split-str "Hello,How,Are,You,Today" ",") "."))
|
||||
txr -p '(cat-str (split-str "Hello,How,Are,You,Today" ",") ".")'
|
||||
Hello.How.Are.You.Today
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue