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"