Backspace (\b) Equivalent in swift language

十年热恋 提交于 2019-12-11 05:49:30

问题


What is the \b equivalent in swift? I have to split a string which is received from server with \b?


回答1:


From "Strings and Characters" in the Swift Reference:

Special Characters in String Literals

String literals can include the following special characters:

  • The escaped special characters \0 (null character), \\ (backslash), \t (horizontal tab), \n (line feed), \r (carriage return), \" (double quote) and \' (single quote)
  • An arbitrary Unicode scalar, written as \u{n}, where n is a 1–8 digit hexadecimal number with a value equal to a valid Unicode code point

So Swift does not have a special character for the backspace character, like \b in the C language. You can use the Unicode special character \u{n}:

let string = "THIS\u{8}IS\u{8}A\u{8}TEST"

or create a string from the Unicode value:

let bs = String(UnicodeScalar(8))
let string = "THIS\(bs)IS\(bs)A\(bs)TEST"


来源:https://stackoverflow.com/questions/39042489/backspace-b-equivalent-in-swift-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!