Skip to content

Instantly share code, notes, and snippets.

@jweinst1
Created November 2, 2016 18:06
Show Gist options
  • Save jweinst1/ebb00e8cfa8cecae7f3cb1bccf2f1ed9 to your computer and use it in GitHub Desktop.
Save jweinst1/ebb00e8cfa8cecae7f3cb1bccf2f1ed9 to your computer and use it in GitHub Desktop.
convert uint8 to string in swift
let a:[UInt8] = [24, 27, 36, 50]
let str = String(bytes:a, encoding: String.Encoding.utf8)
//"$2"
@vkill
Copy link

vkill commented Sep 7, 2018

let str = String(decoding: a, as: UTF8.self)

@Terrykuo
Copy link

"\u{18}\u{1B}$2", not same Answer?

@jhoanrivers
Copy link

i got error when trying to convert this

let decripted = [229, 174, 41, 168, 208, 220, 160, 162, 124, 12, 150, 171, 229, 23, 75, 250, 230, 113, 228, 135, 231, 244, 232, 207, 254, 245, 16, 107, 65, 194, 47, 144, 246, 139, 154, 201, 171, 20, 104, 58, 63, 127, 8, 192, 87, 161, 209, 124]

let sstr = String(bytes:decripted, encoding: .utf8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment