all tasks

This commit is contained in:
Ingy döt Net 2013-04-11 01:07:29 -07:00
parent b83f433714
commit 68f8f3e56b
14735 changed files with 178959 additions and 0 deletions

View file

@ -0,0 +1 @@
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.

View file

@ -0,0 +1,2 @@
---
note: String manipulation

View file

@ -0,0 +1,29 @@
(defun split-at (xs delim)
(if (or (endp xs) (eql (first xs) delim))
(mv nil (rest xs))
(mv-let (before after)
(split-at (rest xs) delim)
(mv (cons (first xs) before) after))))
(defun split (xs delim)
(if (endp xs)
nil
(mv-let (before after)
(split-at xs delim)
(cons before (split after delim)))))
(defun css->strs (css)
(if (endp css)
nil
(cons (coerce (first css) 'string)
(css->strs (rest css)))))
(defun split-str (str delim)
(css->strs (split (coerce str 'list) delim)))
(defun print-with (strs delim)
(if (endp strs)
(cw "~%")
(progn$ (cw (first strs))
(cw (coerce (list delim) 'string))
(print-with (rest strs) delim))))

View file

@ -0,0 +1,49 @@
main:(
OP +:= = (REF FLEX[]STRING in out, STRING item)VOID:(
[LWB in out: UPB in out+1]STRING new;
new[LWB in out: UPB in out]:=in out;
new[UPB new]:=item;
in out := new
);
PROC string split = (REF STRING beetles, STRING substr)[]STRING:(
""" Split beetles where substr is found """;
FLEX[1:0]STRING out;
INT start := 1, pos;
WHILE string in string(substr, pos, beetles[start:]) DO
out +:= STRING(beetles[start:start+pos-2]);
start +:= pos + UPB substr - 1
OD;
IF start > LWB beetles THEN
out +:= STRING(beetles[start:])
FI;
out
);
PROC char split = (REF STRING beetles, STRING chars)[]STRING: (
""" Split beetles where character is found in chars """;
FLEX[1:0]STRING out;
FILE beetlef;
associate(beetlef, beetles); # associate a FILE handle with a STRING #
make term(beetlef, chars); # make term: assign CSV string terminator #
PROC raise logical file end = (REF FILE f)BOOL: except logical file end;
on logical file end(beetlef, raise logical file end);
STRING solo;
DO
getf(beetlef, ($g$, solo));
out+:=solo;
getf(beetlef, ($x$)) # skip CHAR separator #
OD;
except logical file end:
SKIP;
out
);
STRING beetles := "John Lennon, Paul McCartney, George Harrison, Ringo Starr";
printf(($g"."$, string split(beetles, ", "),$l$));
printf(($g"."$, char split(beetles, ", "),$l$))
)

View file

@ -0,0 +1,8 @@
BEGIN {
s = "Hello,How,Are,You,Today"
split(s, arr, ",")
for(i=1; i < length(arr); i++) {
printf arr[i] "."
}
print
}

View file

@ -0,0 +1,5 @@
BEGIN { FS = "," }
{
for(i=1; i <= NF; i++) printf $i ".";
print ""
}

View file

@ -0,0 +1,6 @@
var hello:String = "Hello,How,Are,You,Today";
var tokens:Array = hello.split(",");
trace(tokens.join("."));
// Or as a one-liner
trace("Hello,How,Are,You,Today".split(",").join("."));

View file

@ -0,0 +1,18 @@
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Text_Io; use Ada.Text_Io;
procedure Parse_Commas is
Source_String : String := "Hello,How,Are,You,Today";
Index_List : array(Source_String'Range) of Natural;
Next_Index : Natural := Index_List'First;
begin
Index_List(Next_Index) := Source_String'First;
while Index_List(Next_Index) < Source_String'Last loop
Next_Index := Next_Index + 1;
Index_List(Next_Index) := 1 + Index(Source_String(Index_List(Next_Index - 1)..Source_String'Last), ",");
if Index_List(Next_Index) = 1 then
Index_List(Next_Index) := Source_String'Last + 2;
end if;
Put(Source_String(Index_List(Next_Index - 1)..Index_List(Next_Index)-2) & ".");
end loop;
end Parse_Commas;

View file

@ -0,0 +1,6 @@
string := "Hello,How,Are,You,Today"
stringsplit, string, string, `,
loop, % string0
{
msgbox % string%A_Index%
}

View file

@ -0,0 +1,45 @@
DIM parseMe AS STRING
parseMe = "Hello,How,Are,You,Today"
DIM tmpLng1 AS INTEGER, tmpLng2 AS INTEGER, parsedCount AS INTEGER
tmpLng2 = 1
parsedCount = -1
'count number of tokens
DO
tmpLng1 = INSTR(tmpLng2, parseMe, ",")
IF tmpLng1 THEN
parsedCount = parsedCount + 1
tmpLng2 = tmpLng1 + 1
ELSE
IF tmpLng2 < (LEN(parseMe) + 1) THEN parsedCount = parsedCount + 1
EXIT DO
END IF
LOOP
IF parsedCount > -1 THEN
REDIM parsed(parsedCount) AS STRING
tmpLng2 = 1
parsedCount = -1
'parse
DO
tmpLng1 = INSTR(tmpLng2, parseMe, ",")
IF tmpLng1 THEN
parsedCount = parsedCount + 1
parsed(parsedCount) = MID$(parseMe, tmpLng2, tmpLng1 - tmpLng2)
tmpLng2 = tmpLng1 + 1
ELSE
IF tmpLng2 < (LEN(parseMe) + 1) THEN
parsedCount = parsedCount + 1
parsed(parsedCount) = MID$(parseMe, tmpLng2)
END IF
EXIT DO
END IF
LOOP
PRINT parsed(0);
FOR L0 = 1 TO parsedCount
PRINT "."; parsed(L0);
NEXT
END IF

View file

@ -0,0 +1,8 @@
INSTALL @lib$+"STRINGLIB"
text$ = "Hello,How,Are,You,Today"
n% = FN_split(text$, ",", array$())
FOR i% = 0 TO n%-1
PRINT array$(i%) "." ;
NEXT
PRINT

View file

@ -0,0 +1,12 @@
@echo off
setlocal enabledelayedexpansion
call :tokenize %1 res
echo %res%
goto :eof
:tokenize
set str=%~1
:loop
for %%i in (%str%) do set %2=!%2!.%%i
set %2=!%2:~1!
goto :eof

View file

@ -0,0 +1,13 @@
( "Hello,How,Are,You,Today":?String
& :?ReverseList
& whl
' ( @(!String:?element "," ?String)
& !element !ReverseList:?ReverseList
)
& !String:?List
& whl
' ( !ReverseList:%?element ?ReverseList
& (!element.!List):?List
)
& out$!List
)

View file

@ -0,0 +1,13 @@
( get$("Hello,How,Are,You,Today",MEM):?CommaseparatedList
& :?ReverseList
& whl
' ( !CommaseparatedList:(?element,?CommaseparatedList)
& !element !ReverseList:?ReverseList
)
& !CommaseparatedList:?List
& whl
' ( !ReverseList:%?element ?ReverseList
& (!element.!List):?List
)
& out$!List
)

View file

@ -0,0 +1,16 @@
#include <string>
#include <sstream>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
int main()
{
std::string s = "Hello,How,Are,You,Today";
std::vector<std::string> v;
std::istringstream buf(s);
for(std::string token; getline(buf, token, ','); )
v.push_back(token);
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."));
std::cout << '\n';
}

View file

@ -0,0 +1,25 @@
#include <string>
#include <locale>
#include <sstream>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
struct comma_ws : std::ctype<char> {
static const mask* make_table() {
static std::vector<mask> v(classic_table(), classic_table() + table_size);
v[','] |= space; // comma will be classified as whitespace
return &v[0];
}
comma_ws(std::size_t refs = 0) : ctype<char>(make_table(), false, refs) {}
};
int main()
{
std::string s = "Hello,How,Are,You,Today";
std::istringstream buf(s);
buf.imbue(std::locale(buf.getloc(), new comma_ws));
std::istream_iterator<std::string> beg(buf), end;
std::vector<std::string> v(beg, end);
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."));
std::cout << '\n';
}

View file

@ -0,0 +1,14 @@
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
#include <iostream>
#include <boost/tokenizer.hpp>
int main()
{
std::string s = "Hello,How,Are,You,Today";
boost::tokenizer<> tok(s);
std::vector<std::string> v(tok.begin(), tok.end());
copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."))
std::cout << '\n';
}

View file

@ -0,0 +1,22 @@
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
char *a[5];
const char *s="Hello,How,Are,You,Today";
int n=0, nn;
char *ds=strdup(s);
a[n]=strtok(ds, ",");
while(a[n] && n<4) a[++n]=strtok(NULL, ",");
for(nn=0; nn<=n; ++nn) printf("%s.", a[nn]);
putchar('\n');
free(ds);
return 0;
}

View file

@ -0,0 +1,26 @@
#include<stdio.h>
typedef (void *callbackfunc)(const char *);
void doprint(const char *s) {
printf("%s.", s);
}
void tokenize(char *s, char delim, callbackfunc *cb) {
char *olds = s;
char olddelim = delim;
while(olddelim && *s) {
while(*s && (delim != *s)) s++;
*s ^= olddelim = *s; // olddelim = *s; *s = 0;
cb(olds);
*s++ ^= olddelim; // *s = olddelim; s++;
olds = s;
}
}
int main(void)
{
char array[] = "Hello,How,Are,You,Today";
tokenize(array, ',', doprint);
return 0;
}

View file

@ -0,0 +1 @@
(apply str (interpose "." (seq (.split #"," "Hello,How,Are,You,Today"))))

View file

@ -0,0 +1,2 @@
arr = "Hello,How,Are,You,Today".split ","
console.log arr.join "."

View file

@ -0,0 +1,8 @@
(defun comma-split (string)
(loop for start = 0 then (1+ finish)
for finish = (position #\, string :start start)
collecting (subseq string start finish)
until (null finish)))
(defun write-with-periods (strings)
(format t "~{~A~^.~}" strings))

View file

@ -0,0 +1,5 @@
import std.stdio, std.string;
void main() {
"Hello,How,Are,You,Today".split(",").join(".").writeln();
}

View file

@ -0,0 +1,32 @@
program TokenizeString;
{$APPTYPE CONSOLE}
uses
Classes;
var
tmp: TStringList;
i: Integer;
begin
// Instantiate TStringList class
tmp := TStringList.Create;
try
{ Use the TStringList's CommaText property to get/set
all the strings in a single comma-delimited string }
tmp.CommaText := 'Hello,How,Are,You,Today';
{ Now loop through the TStringList and display each
token on the console }
for i := 0 to Pred(tmp.Count) do
Writeln(tmp[i]);
finally
tmp.Free;
end;
Readln;
end.

View file

@ -0,0 +1,5 @@
Hello
How
Are
You
Today

View file

@ -0,0 +1 @@
".".rjoin("Hello,How,Are,You,Today".split(","))

View file

@ -0,0 +1,7 @@
-module(tok).
-export([start/0]).
start() ->
Lst = string:tokens("Hello,How,Are,You,Today",","),
io:fwrite("~s~n", [string:join(Lst,".")]),
ok.

View file

@ -0,0 +1,22 @@
function split(sequence s, integer c)
sequence out
integer first, delim
out = {}
first = 1
while first<=length(s) do
delim = find_from(c,s,first)
if delim = 0 then
delim = length(s)+1
end if
out = append(out,s[first..delim-1])
first = delim + 1
end while
return out
end function
sequence s
s = split("Hello,How,Are,You,Today", ',')
for i = 1 to length(s) do
puts(1, s[i] & ',')
end for

View file

@ -0,0 +1 @@
"Hello,How,Are,You,Today" "," split "." join print

View file

@ -0,0 +1,12 @@
class Main
{
public static Void main ()
{
str := "Hello,How,Are,You,Today"
words := str.split(',')
words.each |Str word|
{
echo ("${word}. ")
}
}
}

View file

@ -0,0 +1,18 @@
: split ( str len separator len -- tokens count )
here >r 2swap
begin
2dup 2, \ save this token ( addr len )
2over search \ find next separator
while
dup negate here 2 cells - +! \ adjust last token length
2over nip /string \ start next search past separator
repeat
2drop 2drop
r> here over - ( tokens length )
dup negate allot \ reclaim dictionary
2 cells / ; \ turn byte length into token count
: .tokens ( tokens count -- )
1 ?do dup 2@ type ." ." cell+ cell+ loop 2@ type ;
s" Hello,How,Are,You,Today" s" ," split .tokens \ Hello.How.Are.You.Today

View file

@ -0,0 +1,23 @@
PROGRAM Example
CHARACTER(23) :: str = "Hello,How,Are,You,Today"
CHARACTER(5) :: word(5)
INTEGER :: pos1 = 1, pos2, n = 0, i
DO
pos2 = INDEX(str(pos1:), ",")
IF (pos2 == 0) THEN
n = n + 1
word(n) = str(pos1:)
EXIT
END IF
n = n + 1
word(n) = str(pos1:pos1+pos2-2)
pos1 = pos2+pos1
END DO
DO i = 1, n
WRITE(*,"(2A)", ADVANCE="NO") TRIM(word(i)), "."
END DO
END PROGRAM Example

View file

@ -0,0 +1,5 @@
SplitString("Hello,How,Are,You,Today", ",");
# [ "Hello", "How", "Are", "You", "Today" ]
JoinStringsWithSeparator(last, ".");
# "Hello.How.Are.You.Today"

View file

@ -0,0 +1,11 @@
package main
import (
"fmt"
"strings"
)
func main() {
s := "Hello,How,Are,You,Today"
fmt.Println(strings.Join(strings.Split(s, ","), "."))
}

View file

@ -0,0 +1 @@
println 'Hello,How,Are,You,Today'.split(',').join('.')

View file

@ -0,0 +1,16 @@
splitBy :: (a -> Bool) -> [a] -> [[a]]
splitBy _ [] = []
splitBy f list = first : splitBy f (dropWhile f rest) where
(first, rest) = break f list
splitRegex :: Regex -> String -> [String]
joinWith :: [a] -> [[a]] -> [a]
joinWith d xs = concat $ List.intersperse d xs
-- "concat $ intersperse" can be replaced with "intercalate" from the Data.List in GHC 6.8 and later
putStrLn $ joinWith "." $ splitBy (== ',') $ "Hello,How,Are,You,Today"
-- using regular expression to split:
import Text.Regex
putStrLn $ joinWith "." $ splitRegex (mkRegex ",") $ "Hello,How,Are,You,Today"

View file

@ -0,0 +1,6 @@
*Main> mapM_ putStrLn $ takeWhile (not.null) $ unfoldr (Just . second(drop 1). break (==',')) "Hello,How,Are,You,Today"
Hello
How
Are
You
Today

View file

@ -0,0 +1,13 @@
CHARACTER string="Hello,How,Are,You,Today", list
nWords = INDEX(string, ',', 256) + 1
maxWordLength = LEN(string) - 2*nWords
ALLOCATE(list, nWords*maxWordLength)
DO i = 1, nWords
EDIT(Text=string, SePaRators=',', item=i, WordEnd, CoPyto=CHAR(i, maxWordLength, list))
ENDDO
DO i = 1, nWords
WRITE(APPend) TRIM(CHAR(i, maxWordLength, list)), '.'
ENDDO

View file

@ -0,0 +1,6 @@
procedure main()
A := []
"Hello,How,Are,You,Today" ? while put(A, 1(tab(upto(',')|0),=","))
every writes(!A,".")
write()
end

View file

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

View file

@ -0,0 +1,10 @@
s=: 'Hello,How,Are,You,Today'
] t=: <;._1 ',',s
+-----+---+---+---+-----+
|Hello|How|Are|You|Today|
+-----+---+---+---+-----+
; t,&.>'.'
Hello.How.Are.You.Today.
'.' (I.','=s)}s NB. two steps combined
Hello.How.Are.You.Today

View file

@ -0,0 +1,8 @@
require 'strings'
',' splitstring s
+-----+---+---+---+-----+
|Hello|How|Are|You|Today|
+-----+---+---+---+-----+
'.' joinstring ',' splitstring s
Hello.How.Are.You.Today

View file

@ -0,0 +1,2 @@
'"'([ ,~ ,) '","' joinstring ',' splitstring s
"Hello","How","Are","You","Today"

View file

@ -0,0 +1,2 @@
rplc&',.' s
Hello.How.Are.You.Today

View file

@ -0,0 +1 @@
fn;._2 string,','

View file

@ -0,0 +1 @@
fn ((;._2)(@(,&','))) string

View file

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

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 @@
alert( "Hello,How,Are,You,Today".split(",").join(".") );

View file

@ -0,0 +1 @@
'Hello,How,Are,You,Today ', split '. join .

View file

@ -0,0 +1,7 @@
'Note that Liberty Basic's array usage can reach element #10 before having to DIM the array
For i = 0 To 4
array$(i) = Word$("Hello,How,Are,You,Today", (i + 1), ",")
array$ = array$ + array$(i) + "."
Next i
Print Left$(array$, (Len(array$) - 1))

View file

@ -0,0 +1,3 @@
to split :str :sep
output parse map [ifelse ? = :sep ["| |] [?]] :str
end

View file

@ -0,0 +1,6 @@
to split :str :by [:acc []] [:w "||]
if empty? :str [output lput :w :acc]
ifelse equal? first :str :by ~
[output (split butfirst :str :by lput :w :acc)] ~
[output (split butfirst :str :by :acc lput first :str :w)]
end

View file

@ -0,0 +1,2 @@
? show split "Hello,How,Are,You,Today ",
[Hello How Are You Today]

View file

@ -0,0 +1,10 @@
require"re"
record = re.compile[[
record <- ( <field> (',' <field>)* ) -> {} (%nl / !.)
field <- <escaped> / <nonescaped>
nonescaped <- { [^,"%nl]* }
escaped <- '"' {~ ([^"] / '""' -> '"')* ~} '"'
]]
print(unpack(record:match"hello,how,are,you,today"))

View file

@ -0,0 +1,10 @@
str = "Hello,How,Are,You,Today"
tokens = {}
for w in string.gmatch( str, "(%a+)" ) do
tokens[#tokens+1] = w
end
for i = 1, #tokens do
print( tokens[i] )
end

View file

@ -0,0 +1,11 @@
str = "Hello|How|Are|You||Today"
tokens = {}
for w in string.gmatch( str, "([^|]*)|?" ) do
tokens[#tokens+1] = w
end
table.remove(tokens)--pops off the last empty value, because without doing |? we lose the last element.
for i = 1, #tokens do
print( tokens[i] )
end

View file

@ -0,0 +1,11 @@
define(`s',`Hello,How,Are,You,Today')
define(`set',`define(`$1[$2]',`$3')')
define(`get',`defn($1[$2])')
define(`n',0)
define(`fill',
`set(a,n,$1)`'define(`n',incr(n))`'ifelse(eval($#>1),1,`fill(shift($@))')')
fill(s)
define(`j',0)
define(`show',
`ifelse(eval(j<n),1,`get(a,j).`'define(`j',incr(j))`'show')')
show

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,2 @@
>> tokenizeString('Hello,How,Are,You,Today',',')
Hello.How.Are.You.Today

View file

@ -0,0 +1,6 @@
output = ""
for word in (filterString "Hello,How,Are,You,Today" ",") do
(
output += (word + ".")
)
format "%\n" output

View file

@ -0,0 +1,54 @@
sep IS ','
EOS IS 0
NL IS 10
// main registers
p IS $255
tp GREG
c GREG
t GREG
LOC Data_Segment
GREG @
Text BYTE "Hello,How,Are,You,Today",EOS
token BYTE 0
eot IS @+255
LOC #100 % main () {
Main LDA p,Text %
LDA tp,token % initialize pointers
2H LDBU c,p % DO get char
BZ c,5F % break if char == EOS
CMP t,c,sep % if char != sep then
PBNZ t,3F % store char
SET t,NL % terminate token with NL,EOS
STBU t,tp
SET t,EOS
INCL tp,1
STBU t,tp
JMP 4F % continue
3H STBU c,tp % store char
4H INCL tp,1 % update pointers
INCL p,1
JMP 2B % LOOP
5H SET t,NL % terminate last token and buffer
STBU t,tp
SET t,EOS
INCL tp,1
STBU t,tp
% next part is not really necessary
% program runs only once
% INCL tp,1 % terminate buffer
% STBU t,tp
LDA tp,token % reset token pointer
% REPEAT
2H ADD p,tp,0 % start of token
TRAP 0,Fputs,StdOut % output token
ADD tp,tp,p
INCL tp,1 % step to next token
LDBU t,tp
PBNZ t,2B % UNTIL EOB(uffer)
TRAP 0,Halt,0

View file

@ -0,0 +1,7 @@
TOKENS
NEW I,J,INP
SET INP="Hello,how,are,you,today"
NEW I FOR I=1:1:$LENGTH(INP,",") SET INP(I)=$PIECE(INP,",",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"
QUIT

View file

@ -0,0 +1 @@
Row[Riffle[StringSplit["Hello,How,Are,You,Today", ","], "."]]

View file

@ -0,0 +1,13 @@
:- module string_tokenize.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module list, string.
main(!IO) :-
Tokens = string.split_at_char((','), "Hello,How,Are,You,Today"),
io.write_list(Tokens, ".", io.write_string, !IO),
io.nl(!IO).

View file

@ -0,0 +1,18 @@
MODULE Tokenize EXPORTS Main;
IMPORT IO, TextConv;
TYPE Texts = REF ARRAY OF TEXT;
VAR tokens: Texts;
string := "Hello,How,Are,You,Today";
sep := SET OF CHAR {','};
BEGIN
tokens := NEW(Texts, TextConv.ExplodedSize(string, sep));
TextConv.Explode(string, tokens^, sep);
FOR i := FIRST(tokens^) TO LAST(tokens^) DO
IO.Put(tokens[i] & ".");
END;
IO.Put("\n");
END Tokenize.

View file

@ -0,0 +1,14 @@
using System;
using System.Console;
using Nemerle.Utility.NString;
module Tokenize
{
Main() : void
{
def cswords = "Hello,How,Are,You,Today";
WriteLine(Concat(".", $[s | s in cswords.Split(',')]));
// Split() produces an array while Concat() consumes a list
// a quick in place list comprehension takes care of that
}
}

View file

@ -0,0 +1,12 @@
/*NetRexx program *****************************************************
* 20.08.2012 Walter Pachl derived from REXX Version 3
**********************************************************************/
sss='Hello,How,Are,You,Today'
Say 'input string='sss
Say ''
Say 'Words in the string:'
ss =sss.translate(' ',',')
Loop i=1 To ss.words()
Say ss.word(i)'.'
End
Say 'End-of-list.'

View file

@ -0,0 +1,7 @@
let rec split_char sep str =
try
let i = String.index str sep in
String.sub str 0 i ::
split_char sep (String.sub str (i+1) (String.length str - i - 1))
with Not_found ->
[str]

View file

@ -0,0 +1,18 @@
(* [try .. with] structures break tail-recursion,
so we externalise it in a sub-function *)
let string_index str c =
try Some(String.index str c)
with Not_found -> None
let split_char sep str =
let rec aux acc str =
match string_index str sep with
| Some i ->
let this = String.sub str 0 i
and next = String.sub str (i+1) (String.length str - i - 1) in
aux (this::acc) next
| None ->
List.rev(str::acc)
in
aux [] str
;;

View file

@ -0,0 +1,14 @@
let split_char sep str =
let string_index_from i =
try Some (String.index_from str i sep)
with Not_found -> None
in
let rec aux i acc = match string_index_from i with
| Some i' ->
let w = String.sub str i (i' - i) in
aux (succ i') (w::acc)
| None ->
let w = String.sub str i (String.length str - i) in
List.rev (w::acc)
in
aux 0 []

View file

@ -0,0 +1,3 @@
#load "str.cma";;
let split_str sep str =
Str.split (Str.regexp_string sep) str

View file

@ -0,0 +1 @@
String.concat sep strings

View file

@ -0,0 +1,10 @@
bundle Default {
class Parse {
function : Main(args : String[]) ~ Nil {
tokens := "Hello,How,Are,You,Today"->Split(",");
each(i : tokens) {
tokens[i]->PrintLine();
};
}
}
}

View file

@ -0,0 +1,4 @@
NSString *text = @"Hello,How,Are,You,Today";
NSArray *tokens = [text componentsSeparatedByString:@","];
NSString *result = [tokens componentsJoinedByString:@"."];
NSLog(result);

View file

@ -0,0 +1,24 @@
FUNCTION tokenizeString RETURNS CHAR (
i_c AS CHAR
):
DEF VAR ii AS INT.
DEF VAR carray AS CHAR EXTENT.
DEF VAR cresult AS CHAR.
EXTENT( carray ) = NUM-ENTRIES( i_c ).
DO ii = 1 TO NUM-ENTRIES( i_c ):
carray[ ii ] = ENTRY( ii, i_c ).
END.
DO ii = 1 TO EXTENT( carray ).
cresult = cresult + "." + carray[ ii ].
END.
RETURN SUBSTRING( cresult, 2 ).
END FUNCTION. /* tokenizeString */
MESSAGE
tokenizeString( "Hello,How,Are,You,Today" )
VIEW-AS ALERT-BOX.

View file

@ -0,0 +1,3 @@
for T in {String.tokens "Hello,How,Are,You,Today" &,} do
{System.printInfo T#"."}
end

View file

@ -0,0 +1,4 @@
<?php
$str = 'Hello,How,Are,You,Today';
echo implode('.', explode(',', $str));
?>

View file

@ -0,0 +1,21 @@
declare s character (100) initial ('Hello,How,Are,You,Today');
declare n fixed binary (31);
n = tally(s, ',')+1;
begin;
declare table(n) character (50) varying;
declare c character (1);
declare (i, k) fixed binary (31);
table = ''; k = 1;
do i = 1 to length(s);
c = substr(s, i, 1);
if c = ',' then k = k + 1;
else table(k) = table(k) || c;
end;
/* display the table */
table = table || '.';
put skip list (string(table));
end;

View file

@ -0,0 +1,17 @@
program TokenizeString;
{$mode objfpc}{$H+}
const
CHelloStr = 'Hello,How,Are,You,Today';
var
I: Integer;
VResult: string = '';
begin
for I := 1 to Length(CHelloStr) do
if CHelloStr[I] = ',' then
VResult += LineEnding
else
VResult += CHelloStr[I];
WriteLn(VResult);
end.

View file

@ -0,0 +1 @@
'Hello,How,Are,You,Today'.split(',').join('.').say;

View file

@ -0,0 +1 @@
print join('.', split /,/, 'Hello,How,Are,You,Today'), "\n";

View file

@ -0,0 +1,2 @@
(mapcar pack
(split (chop "Hello,How,Are,You,Today") ",") )

View file

@ -0,0 +1 @@
("Hello,How,Are,You,Today" / ",") * ".";

View file

@ -0,0 +1,6 @@
;;; Make a list of strings from a string using space as separator
lvars list;
sysparse_string('the cat sat on the mat') -> list;
;;; print the list of strings
list =>
** [the cat sat on the mat]

View file

@ -0,0 +1,10 @@
lvars list;
sysparse_string('one 1 two 2 three 3 four 4', true) -> list;
;;; print the list of strings and numbers
list =>
** [one 1 two 2 three 3 four 4]
;;; check that first item is a string and second an integer
isstring(list(1))=>
** <true>
isinteger(list(2))=>
** <true>

View file

@ -0,0 +1,15 @@
;;; Make pop-11 print strings with quotes
true -> pop_pr_quotes;
;;;
;;; Create a string of tokens using comma as token separator
lvars str='Hello,How,Are,You,Today';
;;;
;;; Make a list of strings by applying sys_parse_string
;;; to str, using the character `,` as separator (the default
;;; separator, if none is provided, is the space character).
lvars strings;
[% sys_parse_string(str, `,`) %] -> strings;
;;;
;;; print the list of strings
strings =>
** ['Hello' 'How' 'Are' 'You' 'Today']

View file

@ -0,0 +1,4 @@
{% sys_parse_string(str, `,`) %} -> strings;
;;; print the vector
strings =>
** {'Hello' 'How' 'Are' 'You' 'Today'}

View file

@ -0,0 +1,6 @@
lvars numbers;
{% sys_parse_string('100 101 102 103 99.9 99.999', strnumber) %} -> numbers;
;;; the result is a vector containing integers and floats,
;;; which can be printed thus:
numbers =>
** {100 101 102 103 99.9 99.999}

View file

@ -0,0 +1,18 @@
;;; Declare and initialize variables
lvars str='Hello,How,Are,You,Today';
;;; Iterate over string
lvars ls = [], i, j = 1;
for i from 1 to length(str) do
;;; If comma
if str(i) = `,` then
;;; Prepend word (substring) to list
cons(substring(j, i - j, str), ls) -> ls;
i + 1 -> j;
endif;
endfor;
;;; Prepend final word (if needed)
if j <= length(str) then
cons(substring(j, length(str) - j + 1, str), ls) -> ls;
endif;
;;; Reverse the list
rev(ls) -> ls;

View file

@ -0,0 +1,9 @@
;;; Put list elements and lenght on the stack
destlist(ls);
;;; Build a vector from them
lvars ar = consvector();
;;; Display in a loop, putting trailing period
for i from 1 to length(ar) do
printf(ar(i), '%s.');
endfor;
printf('\n');

View file

@ -0,0 +1,3 @@
for i in ls do
printf(i, '%s.');
endfor;

View file

@ -0,0 +1,15 @@
FUNCTION PBMAIN () AS LONG
DIM parseMe AS STRING
parseMe = "Hello,How,Are,You,Today"
REDIM parsed(PARSECOUNT(parseMe) - 1) AS STRING
PARSE parseMe, parsed() 'comma is default delimiter
DIM L0 AS LONG, outP AS STRING
outP = parsed(0)
FOR L0 = 1 TO UBOUND(parsed) 'could reuse parsecount instead of ubound
outP = outP & "." & parsed(L0)
NEXT
MSGBOX outP
END FUNCTION

View file

@ -0,0 +1,2 @@
$words = "Hello,How,Are,You,Today".Split(',')
[string]::Join('.', $words)

View file

@ -0,0 +1,2 @@
$words = "Hello,How,Are,You,Today" -split ','
$words -join '.'

View file

@ -0,0 +1,9 @@
splitup(Sep,[token(B)|BL]) --> splitup(Sep,B,BL).
splitup(Sep,[A|AL],B) --> [A], {\+ [A] = Sep }, splitup(Sep,AL,B).
splitup(Sep,[],[B|BL]) --> Sep, splitup(Sep,B,BL).
splitup(_Sep,[],[]) --> [].
start :-
phrase(splitup(",",Tokens),"Hello,How,Are,You,Today"),
phrase(splitup(".",Tokens),Backtogether),
string_to_list(ABack,Backtogether),
writeln(ABack).

View file

@ -0,0 +1,10 @@
NewList MyStrings.s()
For i=1 To 5
AddElement(MyStrings())
MyStrings()=StringField("Hello,How,Are,You,Today",i,",")
Next i
ForEach MyStrings()
Print(MyStrings()+".")
Next

View file

@ -0,0 +1 @@
Print(ReplaceString("Hello,How,Are,You,Today",",","."))

View file

@ -0,0 +1,3 @@
text = "Hello,How,Are,You,Today"
tokens = text.split(',')
print ('.'.join(tokens))

View file

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

Some files were not shown because too many files have changed in this diff Show more