Skip to content

Instantly share code, notes, and snippets.

@paneq
Created July 7, 2014 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paneq/0ecfc96c0d093a97e0e7 to your computer and use it in GitHub Desktop.
Save paneq/0ecfc96c0d093a97e0e7 to your computer and use it in GitHub Desktop.
slicing ruby string to bytes (because APNS) and making it still look good
"777żółć".byteslice(0,6).scrub("")
"777żółć".byteslice(0,7).scrub("")
"777żółć".byteslice(0,8).scrub("")
"777żółć".byteslice(0,9).scrub("")
[20] pry(main)> "777żółć".byteslice(0,6).scrub("")
=> "777ż"
[21] pry(main)> "777żółć".byteslice(0,7).scrub("")
=> "777żó"
[22] pry(main)> "777żółć".byteslice(0,8).scrub("")
=> "777żó"
[23] pry(main)> "777żółć".byteslice(0,9).scrub("")
=> "777żół"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment