Convert string to ASCII value python
You can use a list comprehension: >>> s=”hi” >>> [ord(c) for c in s] [104, 105]
You can use a list comprehension: >>> s=”hi” >>> [ord(c) for c in s] [104, 105]
I’ve read this question long time ago, and finished writing my own pretty-printer for tables: tabulate. My use case is: I want a one-liner most of the time which is smart enough to figure the best formatting for me and can output different plain-text formats Given your example, grid is probably the most similar output … Read more
Two options: char c1 = ‘\u0001’; char c1 = (char) 1;
Straightforward way: char digits[] = {‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’ }; char aChar = digits[i]; Safer way: char aChar=”0″ + i; Generic way: itoa(i, …) Handy way: sprintf(myString, “%d”, i) C++ way: (taken from Dave18 answer) std::ostringstream oss; oss << 6; Boss way: Joe, write me an int to char … Read more
For ASCII characters in the range [ -~] on Python 2: >>> import binascii >>> bin(int(binascii.hexlify(‘hello’), 16)) ‘0b110100001100101011011000110110001101111’ In reverse: >>> n = int(‘0b110100001100101011011000110110001101111’, 2) >>> binascii.unhexlify(‘%x’ % n) ‘hello’ In Python 3.2+: >>> bin(int.from_bytes(‘hello’.encode(), ‘big’)) ‘0b110100001100101011011000110110001101111’ In reverse: >>> n = int(‘0b110100001100101011011000110110001101111’, 2) >>> n.to_bytes((n.bit_length() + 7) // 8, ‘big’).decode() ‘hello’ To support all … Read more
[ -~] It was seen here. It matches all ASCII characters from the space to the tilde. So your implementation would be: xxx[ -~]+xxx
I would choose “Unit Separator” ASCII code “US”: ASCII 31 (0x1F) In the old, old days, most things were done serially, without random access. This meant that a few control codes were embedded into ASCII. ASCII 28 (0x1C) File Separator – Used to indicate separation between files on a data input stream. ASCII 29 (0x1D) … Read more
If String#ord didn’t exist in 1.9, it does in 2.0: “A”.ord #=> 65
One line printf “\x$(printf %x 65)” Two lines set $(printf %x 65) printf “\x$1” Here is one if you do not mind using awk awk ‘BEGIN{printf “%c”, 65}’
Likely, your problem is that you parsed it okay, and now you’re trying to print the contents of the XML and you can’t because theres some foreign Unicode characters. Try to encode your unicode string as ascii first: unicodeData.encode(‘ascii’, ‘ignore’) the ‘ignore’ part will tell it to just skip those characters. From the python docs: … Read more