Backspace (\b) Equivalent in swift language

2019-09-14 02:07发布

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

1条回答
我只想做你的唯一
2楼-- · 2019-09-14 02:35

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"
查看更多
登录 后发表回答