Many languages have powerful and useful (binary safe) string manipulation functions, while others don't, making it harder for these languages to accomplish some tasks.

This task is about creating functions to handle binary strings (strings made of arbitrary bytes, i.e. byte strings according to Wikipedia) for those languages that don't have built-in support for them.

If your language of choice does have this built-in support, show a possible alternative implementation for the functions or abilities already provided by the language.

In particular the functions you need to create are:

 String creation and destruction (when needed and if there's no garbage collection or similar mechanism)
 String assignment
 String comparison
 String cloning and copying
 Check if a string is empty
 Append a byte to a string
 Extract a substring from a string
 Replace every occurrence of a byte (or a string) in a string with another string
 Join strings


Possible contexts of use: compression algorithms (like LZW compression), L-systems (manipulation of symbols), many more.




s := "abc"             # create a string (immutable if its a literal constant in the program)
s := #[16r01 16r02 16r00 16r03] asString # strings can contain any value, even nulls
s := String new:3.     # a mutable string
v := s                 # assignment
s = t                  # same contents
s < t                  # less
s <= t                 # less or equal
s = ''                 # equal empty string
s isEmpty              # ditto
s size                 # string length
t := s copy            # a copy
t := s copyFrom:2 to:3 # a substring
t := s copyReplaceFrom:2 to:3 with:'**'  # a copy with some replacements
s replaceFrom:2 to:3 with:'**'           # inplace replace (must be mutable)
s replaceAll:$x with:$y                  # destructive replace of characters
s copyReplaceAll:$x with:$y              # non-destructive replace
s replaceString:s1 withString:s2         # substring replace
s3 := s1 , s2          # concatenation of strings
s2 := s1 , $x          # append a character
s2 := s1 , 123 asCharacter # append an arbitrary byte
s := 'Hello / 今日は'   # they support unicode (at least up to 16rFFFF, some more)