September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,18 +1,24 @@
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Text_Io; use Ada.Text_Io;
with Ada.Text_IO, Ada.Strings.Fixed, Ada.Containers.Indefinite_Vectors;
use Ada.Text_IO, Ada.Strings.Fixed, Ada.Containers;
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;
procedure tokenize is
package String_Vector is new Indefinite_Vectors (Natural,String); use String_Vector;
procedure Parse (s : String; v : in out Vector) is
i : Integer := Index (s,",");
begin
if s'Length > 0 then
if i < s'First then
v.Append (s);
else
v.Append (s (s'First..i-1));
Parse ( s(i+1..s'Last), v);
end if;
Put(Source_String(Index_List(Next_Index - 1)..Index_List(Next_Index)-2) & ".");
end loop;
end Parse_Commas;
end if;
end Parse;
v : Vector;
begin
Parse ("Hello,How,Are,You,Today,,",v);
for s of v loop
put(s&".");
end loop;
end tokenize;

View file

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

View file

@ -1,14 +1,5 @@
Sub Main()
Dim parseMe As String, parsed As Variant
parseMe = "Hello,How,Are,You,Today"
parsed = Split(parseMe, ",")
Dim L0 As Long, outP As String
outP = parsed(0)
For L0 = 1 To UBound(parsed)
outP = outP & "." & parsed(L0)
Next
MsgBox outP
End Sub
text$ = "Hello,How,Are,You,Today"
FOR i = 1 to 5
textArray$(i) = word$(text$,i,",")
print textArray$(i);" ";
NEXT

View file

@ -0,0 +1 @@
WScript.Echo Join(Split("Hello,How,Are,You,Today", ","), ".")

View file

@ -1,8 +1,13 @@
INSTALL @lib$+"STRINGLIB"
' Tokenize a string
OPTION BASE 1
text$ = "Hello,How,Are,You,Today"
n% = FN_split(text$, ",", array$())
FOR i% = 0 TO n%-1
PRINT array$(i%) "." ;
NEXT
PRINT
READ csv$
DATA "Hello,How,Are,You,Today"
SPLIT csv$ BY "," TO elements$ SIZE n
FOR i = 1 TO n
PRINT elements$[i] FORMAT "%s"
IF i < n THEN PRINT "." FORMAT "%s"
NEXT
PRINT

View file

@ -1,7 +1,8 @@
'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
INSTALL @lib$+"STRINGLIB"
Print Left$(array$, (Len(array$) - 1))
text$ = "Hello,How,Are,You,Today"
n% = FN_split(text$, ",", array$())
FOR i% = 0 TO n%-1
PRINT array$(i%) "." ;
NEXT
PRINT

View file

@ -1,15 +1,17 @@
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
10 REM TOKENIZE A STRING ... ROSETTACODE.ORG
20 T$ = "HELLO,HOW,ARE,YOU,TODAY"
30 GOSUB 200, TOKENIZE
40 FOR I = 1 TO N
50 PRINT A$(I) "." ;
60 NEXT
70 PRINT
80 END
200 IF N = 0 THEN DIM A$(256)
210 N = 1
220 A$(N) = ""
230 FOR L = 1 TO LEN(T$)
240 C$ = MID$(T$, L, 1)
250 IF C$<>"," THEN A$(N) = A$(N) + C$: GOTO 270
260 N = N + 1
270 NEXT L
280 RETURN

View file

@ -1,10 +1,7 @@
NewList MyStrings.s()
For i=1 To 5
AddElement(MyStrings())
MyStrings()=StringField("Hello,How,Are,You,Today",i,",")
'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
ForEach MyStrings()
Print(MyStrings()+".")
Next
Print Left$(array$, (Len(array$) - 1))

View file

@ -1 +1,15 @@
Print(ReplaceString("Hello,How,Are,You,Today",",","."))
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

@ -1,45 +1,10 @@
DIM parseMe AS STRING
parseMe = "Hello,How,Are,You,Today"
NewList MyStrings.s()
DIM tmpLng1 AS INTEGER, tmpLng2 AS INTEGER, parsedCount AS INTEGER
tmpLng2 = 1
parsedCount = -1
For i=1 To 5
AddElement(MyStrings())
MyStrings()=StringField("Hello,How,Are,You,Today",i,",")
Next i
'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
ForEach MyStrings()
Print(MyStrings()+".")
Next

View file

@ -1,5 +1 @@
text$ = "Hello,How,Are,You,Today"
FOR i = 1 to 5
textArray$(i) = word$(text$,i,",")
print textArray$(i);" ";
NEXT
Print(ReplaceString("Hello,How,Are,You,Today",",","."))

View file

@ -1 +1,45 @@
WScript.Echo Join(Split("Hello,How,Are,You,Today", ","), ".")
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

@ -1,8 +0,0 @@
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,4 @@
<cfoutput>
<cfset wordListTag = "Hello,How,Are,You,Today">
#Replace( wordListTag, ",", ".", "all" )#
</cfoutput>

View file

@ -0,0 +1,5 @@
<cfscript>
wordList = "Hello,How,Are,You,Today";
splitList = replace( wordList, ",", ".", "all" );
writeOutput( splitList );
</cfscript>

View file

@ -1,12 +1,12 @@
#import system.
#import system'routines.
import system'routines.
import extensions.
#symbol program =
program =
[
#var string := "Hello,How,Are,You,Today".
var string := "Hello,How,Are,You,Today".
string split &by:"," run &each:s
string split by:","; forEach(:s)
[
console writeLiteral:(s + ".").
].
console print(s,".")
]
].

View file

@ -1,2 +1,4 @@
val input = "Hello,How,Are,You,Today"
println(input.split(',').join("."))
fun main(args: Array<String>) {
val input = "Hello,How,Are,You,Today"
println(input.split(',').joinToString("."))
}

View file

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

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

@ -1,3 +0,0 @@
| ?- spliting::convert('Hello,How,Are,You,Today', Converted).
Converted = 'Hello.How.Are.You.Today'
yes

View file

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

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

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

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

@ -1,2 +0,0 @@
>> tokenizeString('Hello,How,Are,You,Today',',')
Hello.How.Are.You.Today

View file

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

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

View file

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

View file

@ -0,0 +1,5 @@
text='Hello,How,Are,You,Today'
do while text \= ''
parse var text word1 ',' text
call charout 'STDOUT:',word1'.'
end

View file

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

View file

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

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

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

View file

@ -1,5 +0,0 @@
text$ = "Hello,How,Are,You,Today"
FOR i = 1 to 5
textArray$(i) = word$(text$,i,",")
print textArray$(i);" ";
NEXT

View file

@ -1,5 +1,5 @@
let text = "Hello,How,Are,You,Today"
let tokens = text.characters.split(",").map{String($0)} // for single-character separator
let tokens = text.components(separatedBy: ",") // for single or multi-character separator
print(tokens)
let result = tokens.joinWithSeparator(".")
let result = tokens.joined(separator: ".")
print(result)

View file

@ -1,5 +1,5 @@
let text = "Hello,How,Are,You,Today"
let tokens = split(text, { $0 == "," }) // for single-character separator
println(tokens)
let result = ".".join(tokens)
println(result)
let tokens = text.characters.split(",").map{String($0)} // for single-character separator
print(tokens)
let result = tokens.joinWithSeparator(".")
print(result)

View file

@ -1,5 +1,5 @@
import Foundation
let text = "Hello,How,Are,You,Today"
let tokens = text.componentsSeparatedByString(",")
print(tokens)
let tokens = split(text, { $0 == "," }) // for single-character separator
println(tokens)
let result = ".".join(tokens)
println(result)

View file

@ -0,0 +1,5 @@
import Foundation
let text = "Hello,How,Are,You,Today"
let tokens = text.componentsSeparatedByString(",")
print(tokens)

View file

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