c strings - How to get length of a CString (UTF8String)in Swift? -
i having cstring
let parametercstring = (parameter nsstring).utf8string now want find length of parametercstring want use
let utf8parameter = nsdata(bytes: parametercstring, length: ) and means same
let utf8parameter:nsdata = parameter.datausingencoding(nsutf8stringencoding, allowlossyconversion: false)!
you can use strlen() function.
let astring:string = "mystring" let acstring = astring.cstringusingencoding(nsutf8stringencoding) let length = strlen(acstring)// returns uint let utf8parameter = nsdata(bytes: acstring, length: length)
Comments
Post a Comment