Create a gist now

Instantly share code, notes, and snippets.

class Main
public static void main(String[] args) throws Exception
byte[] buffer = {0x53, 0x6f, 0x08, 0x6e, 0x69, 0x01, 0x63}; // 'S', 'o', '^?' (Backspace), 'n', 'i', '^A' (SOH), 'c'
String str = new String(buffer, "US-ASCII");
System.out.println("String: " + str);
System.out.println("Trimmed string: " + str.replaceAll("[^\\p{Print}]",""));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment