This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1 @@
"Hello, byte-array!" utf8 encode .

View file

@ -0,0 +1 @@
B{ 147 250 150 123 } shift-jis decode .

View file

@ -0,0 +1,14 @@
s := "\x00" # strings can contain any value, even nulls
s := "abc" # create a string
s := &null # destroy a string (well sbsnfon it for garbage collection)
v := s # assignment
s == t # expression s equals t
s << t # expression s less than t
s <<= t # expression s less than or equal to t
v := s # strings are immutable, no copying or cloning are needed
s == "" # equal empty string
*s = 0 # string length is zero
s ||:= "a" # append a byte "a" to s via concatenation
t := s[2+:3] # t is set to position 2 for 3 characters
s := replace(s,s2,s3) # IPL replace function
s := s1 || s2 # concatenation (joining) of strings

View file

@ -0,0 +1,16 @@
procedure replace(s1, s2, s3) #: string replacement
local result, i
result := ""
i := *s2
if i = 0 then fail # would loop on empty string
s1 ? {
while result ||:= tab(find(s2)) do {
result ||:= s3
move(i)
}
return result || tab(0)
}
end

View file

@ -0,0 +1 @@
name=: ''

View file

@ -0,0 +1 @@
'string1','string2'

View file

@ -0,0 +1 @@
n{a.

View file

@ -0,0 +1 @@
1 0 255{a.

View file

@ -0,0 +1 @@
name=: 0

View file

@ -0,0 +1 @@
name=: 'value'

View file

@ -0,0 +1 @@
name1 -: name2

View file

@ -0,0 +1,2 @@
name1= 'example'
name2= name1

View file

@ -0,0 +1 @@
0=#string

View file

@ -0,0 +1,3 @@
string=: 'example'
byte=: DEL
string=: string,byte

View file

@ -0,0 +1 @@
3{.5}.'The quick brown fox runs...'

View file

@ -0,0 +1,2 @@
require 'strings'
'The quick brown fox runs...' rplc ' ';' !!! '

View file

@ -0,0 +1,33 @@
'string creation
s$ = "Hello, world!"
'string destruction - not needed because of garbage collection
s$ = ""
'string comparison
s$ = "Hello, world!"
If s$ = "Hello, world!" then print "Equal Strings"
'string copying
a$ = s$
'check If empty
If s$ = "" then print "Empty String"
'append a byte
s$ = s$ + Chr$(33)
'extract a substring
a$ = Mid$(s$, 1, 5)
'replace bytes
a$ = "Hello, world!"
for i = 1 to len(a$)
if mid$(a$,i,1)="l" then
a$=left$(a$,i-1)+"L"+mid$(a$,i+1)
end if
next
print a$
'join strings
s$ = "Good" + "bye" + " for now."

View file

@ -0,0 +1,19 @@
(* String creation and destruction *) BinaryString = {}; BinaryString = . ;
(* String assignment *) BinaryString1 = {12,56,82,65} , BinaryString2 = {83,12,56,65}
-> {12,56,82,65}
-> {83,12,56,65}
(* String comparison *) BinaryString1 === BinaryString2
-> False
(* String cloning and copying *) BinaryString3 = BinaryString1
-> {12,56,82,65}
(* Check if a string is empty *) BinaryString3 === {}
-> False
(* Append a byte to a string *) AppendTo[BinaryString3, 22]
-> {12,56,82,65,22}
(* Extract a substring from a string *) Take[BinaryString3, {2, 5}]
-> {56,82,65,22}
(* Replace every occurrence of a byte (or a string) in a string with another string *)
BinaryString3 /. {22 -> Sequence[33, 44]}
-> {12,56,82,65,33,44}
(* Join strings *) BinaryString4 = Join[BinaryString1 , BinaryString2]
-> {12,56,82,65,83,12,56,65}