Data update

This commit is contained in:
Ingy döt Net 2025-02-27 18:35:13 -05:00
parent 8e4e15fa56
commit 72eb4943cb
1853 changed files with 35514 additions and 9441 deletions

View file

@ -0,0 +1,31 @@
uses sysutils;
var
{ declaration is creation }
a,b:string;
{ creation with default value }
c:string = 'this is a string';
begin
{ assignment }
a := 'test';
b := 'test';
writeln(a:6, b:6);
{ comparison }
writeln('equal? ', a = b );
{ empty string }
writeln('empty? ', a = '');
{ cloning, copying }
a := c;
writeln('copy c to a, a is now: ', a);
{ append }
b := b +'W';
writeln('append W to b: ',b);
{ extract substring }
b := copy(a,6,2);
writeln('this should be is": ',b);
{ replace }
a := stringreplace(a,'i','I',[rfReplaceAll]);
writeln('replace i with I: ',a);
{ join }
a:= concat(b,c);
writeln('join b and c; ',a);
end.

View file

@ -0,0 +1,51 @@
' String assignment
a$="alfa"
string a="beta"
b="beta too"
all=a$+a+b
Print All
' String comparison
Print a$=a, a=b, a+A+" too"+a$=a+b+a$ ' false false true
b$=a$
// compare return 0 for equal (-1,0, 1),
//same as <=> but compare work with variables only (without coping values)
print "using compare", compare(a$, b$), a$<=>b$ ' 0 0
' String cloning and copying
a2$=a$ ' copy
' Check if a string is empty
print a2$="", len(a$)=0
' Append a byte to a string
c$=Str$("ABCDE") ' utf16le "ABCDE" convert to ANSI (one byte per code)
Print len(c$)=2.5 ' measure 16bit, so we get 2.5x2=5 bytes
c$+=Str$("Z")
Print Len(c$)=3
Print chr$(c$)="ABCDEZ" ' convert to UTF16LE and then compare
' Extract a substring from a string
Print chr$(mid$(c$,2, 2 as byte))="BC"
Print mid$("ABCDEZ",2,2) ="BC"
' Replace every occurrence of a byte (or a string) in a string with another string
Print Replace$("BC", "?", "ABCDEZBC")="A?DEZ?"
Print Replace$("BC", "?", CHR$(c$))="A?DEZ"
' String creation and destruction (using buffers. Memory Blocks)
' (when needed and if there's no garbage collection or similar mechanism)
'Join strings (IN A BUFFRT)
buffer clear K as byte*10 ' using clear to erase the buffer with 0
Return K, 0:=c$
Print eval(k, 2)=asc("C"), eval(k, 3)=asc("D")
Return k, 2:=str$("KL")
Print chr$(eval$(k, 0, 6))="ABKLEZ"
' rotate one byte
M= eval(K,0)
return k, 0:=eval$(k, 1, 5), 5:=m ' we can place strings or bytes at specific index - from 0.
Print chr$(eval$(k, 0, 6))="BKLEZA" ' true
// change length of buffer
buffer K as byte*6
// now we get the full string (with the length of 6 bytes)
Print chr$(eval$(k))="BKLEZA" ' true
buffer K1 as byte*6
// buffers are special objects, so we have strings refering by object pointer.
// we can pass the buffer pointer or return it from a function, also we can swap variables for buffers
swap K, k1
Print chr$(eval$(k1))="BKLEZA" ' true
// we can get the address of string:
Print k1(0) ' return the absolute address of byte at offset 0 on k1 buffer

View file

@ -0,0 +1,48 @@
# string creation
var x = "hello world"
# string destruction
x = nil
# string assignment with a null byte
x = "a\0b"
say x.length # ==> 3
# string comparison
if (x == "hello") {
say "equal"
} else {
say "not equal"
}
var y = 'bc'
if (x < y) {
say "#{x} is lexicographically less than #{y}"
}
# string cloning
var xx = x.clone
say (x == xx) # true, same length and content
say (x.refaddr == xx.refaddr) # false, different objects
# check if empty
if (x.is_empty) {
say "is empty"
}
# append a byte
x += "\07"
say x.dump #=> "a\0b\a"
# substring
say x.substr(0, -1).dump #=> "a\0b"
# replace bytes
say "hello world".tr("l", "L")
# join strings
var a = "hel"
var b = "lo w"
var c = "orld"
var d = (a + b + c)
say d