Ruby: character to ascii from a string
The c variable already contains the char code! “string”.each_byte do |c| puts c end yields 115 116 114 105 110 103
The c variable already contains the char code! “string”.each_byte do |c| puts c end yields 115 116 114 105 110 103
htop author here. No, there’s no “nice” way to get the output of htop piped into a file. It is an interactive application and uses terminal redraw routines to produce its interface (therefore, piping it makes as much sense as, for example, piping vim into a text file — you’ll get similar results). To get … Read more
Mac OS X’s “Keychain Access” application gives you access to the nice OS X password generator. Hit command-N and click the key icon. You get to choose password style (memorable, numeric, alphanumeric, random, FIPS-181) and choose the length. It also warns you about weak passwords.
The Chr function in VB.NET converts the integer back to the character: Dim i As Integer = Asc(“x”) ‘ Convert to ASCII integer. Dim x As Char = Chr(i) ‘ Convert ASCII integer to char.
If you want to clear the screen, the “ANSI” sequence in a printf \033[2J clears the entire screen, e.g., printf ‘\033[2J’ The command-line clear program uses this, along with moving the cursor to the “home” position, again an “ANSI” sequence: \033[H The program gets the information from the terminal database. For example, for TERM=vt100, it … Read more
This is how you can work with ASCII values and NSString. Note that since NSString is working with unichars, there could be unexpected results for a non ASCII string. // NSString to ASCII NSString *string = @”A”; int asciiCode = [string characterAtIndex:0]; // 65 // ASCII to NSString int asciiCode = 65; NSString *string = … Read more
Well, you could create a wrapper that retrieves the data as UTF-8 bytes and converts pieces as needed to System.String, then vice-versa to push the string back out to memory. The Encoding class will help you out here: var utf8 = Encoding.UTF8; byte[] utfBytes = utf8.GetBytes(myString); var myReturnedString = utf8.GetString(utfBytes);
The easiest way I’ve found: var str = “Rånades på Skyttis i Ö-vik”; var combining = /[\u0300-\u036F]/g; console.log(str.normalize(‘NFKD’).replace(combining, ”)); For reference see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize
Depending on your machine you can try piping your strings through iconv -f utf-8 -t ascii//translit (or whatever your encoding is, if it’s not utf-8)
If you care about portability, you’ll drop echo and use printf(1): printf ‘\012’