Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -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]]

View file

@ -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;
}

View file

@ -0,0 +1,2 @@
tokens = String.split("Hello,How,Are,You,Today", ",")
IO.puts Enum.join(tokens, ".")

View file

@ -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(",")));

View file

@ -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] + ".");
}

View 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() + ".");
}

View 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.

View 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

View file

@ -0,0 +1 @@
(print (join (parse "Hello,How,Are,You,Today" ",") "."))

View file

@ -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;

View file

@ -0,0 +1 @@
echo "Hello,How,Are,You,Today" | perl -aplF/,/ -e '$" = "."; $_ = "@F";'

View 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 $_;
}

View 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

View file

@ -0,0 +1,4 @@
(print
(string-join
(string-split "Hello,How,Are,You,Today" #\,)
"."))

View file

@ -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