Binary strings: Difference between revisions

m
→‎[[Basic_string_manipulation_functions#ALGOL 68]]: add heap creation, and prepending strings
m (→‎[[Basic_string_manipulation_functions#ALGOL 68]]: add index substring replacement)
m (→‎[[Basic_string_manipulation_functions#ALGOL 68]]: add heap creation, and prepending strings)
Line 28:
b := ();
BEGIN
LOC STRING lb := "ABCDhello earth"; # allocate off the LOC stack #
HEAP STRING hb := "hello moon"; # allocate out of the HEAP space #
~
END; # local variable "lb" has memoryLOC stack space recovered at END #
 
# String assignment #
Line 61 ⟶ 62:
# Append a string to a string #
h +:= "BCD";
h PLUSAB "EFG";
 
# Prepend a string to a string - because STRING addition isn't communitive #
"789" +=: h;
"456" PLUSTO h;
print(("The result of prepends and appends: ", h, new line));
 
# Extract a substring from a string #
Line 81 ⟶ 88:
 
INT offset = 7;
# Replace a character at an offestoffset in the string #
j[offset] := "P";
print(("After replace 7th character: ", j, new line));
 
# Replace a substring at an offestoffset in the string #
j[offset:offset+3] := "PlAN";
print(("After replace 7:10th characters: ", j, new line));
 
# Insert a string before an offestoffset in the string #
j := j[:offset-1]+"INSERTED "+j[offset:];
print(("Insert string before 7th character: ", j, new line));
Line 118 ⟶ 125:
g is empty
g is empty
The result of prepends and appends: 456789ABCDEFG
Substring 2:3 of ABCD456789ABCDEFG is BC56
After replace string: hello planet
After replace 7th character: hello Planet