mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
[golfscript/en-en] Add some nifty string tricks (#4945)
This commit is contained in:
parent
bb91dc603b
commit
8ceeec19fd
@ -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
|
||||
########################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user