How to I get the Fixnum returned by the following:
"abc"[2]
Back into a character?
To convert ASCII code to a character, you can use different methods such as Type Casting, toString() method, and toChars() method of the Character class. The toString() method will return a character as a String, while the toChars() method returns the array of characters.
The Microsoft Excel CHAR function returns the character based on the ASCII value. The CHAR function is a built-in function in Excel that is categorized as a String/Text Function. It can be used as a worksheet function (WS) in Excel.
The Char function converts a decimal ASCII code into its associated character. This function supports returning any of the standard 128 characters assigned an ASCII code.
In Python 3, the ord () function works to obtain the ASCII value of a character. The function requires a character to be passed as its parameter. It will return the corresponding ASCII value.
This will do it (if n is an integer):
n.chr
Be careful because Ruby 1.9 and later will return a single-character string for "abc"[2]
, which will not respond to the chr
method. You could do this instead:
"abc"[2,1]
Be sure to read up on the powerful and multifaceted String#[] method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With