[golfscript/en-en] Add some nifty string tricks (#4945)

This commit is contained in:
Nicholas Georgescu 2024-05-14 18:47:58 -04:00 committed by GitHub
parent bb91dc603b
commit 8ceeec19fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -242,7 +242,18 @@ I drive a stick, BTW.
[]
> '22222'{+}* # note that if you fold-sum a string not in an array, you'll
# get the sum of the ascii values. '2' is 50, so five times that is:
250
[250]
> ]; # this actually is a clever trick to get ascii values into an array.
[]
> "aabc" [{""+~}*] # if you fold over addition and drop it into a string:
[[97 97 98 99]]
> {[.]""^}%""+ # which can be returned to a string as such using a ""^ map.
# and an empty string join.
["aabc"]
> {32-}% # note that most mapping operations work on the ascii values as
# you would expect, for instance with the difference between A and a being
# 32, you can just subtract that from the ascii value to get:
["AABC"]
> ]; ###################################################################
# blocks
########################################################################