我正在尝试删除Swift String中的引用,例如:“你好啊”因此Swift String就相当于:你好
String
ippsafx71#
您只需使用
雨燕1
var str: String = "\"Hello\"" print(str) // "Hello" print(str.stringByReplacingOccurrencesOfString("\"", withString: "")) // Hello
Swift 3和4的更新
print(str.replacingOccurrences(of: "\"", with: "")) // Hello
5lwkijsr2#
"\"Hello\"".stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: "\""))
nnsrf1az3#
在斯威夫特3中:
let myString = "\"Hello\"" print(myString) // "Hello" let myNewString = myString.replacingOccurrences(of: "\"", with: "") print(myNewString) // Hello
n8ghc7c14#
str.stringByReplacingOccurrencesOfString("\"", withString: "")
ryoqjall5#
//这样尝试
var strString = "\"Hello\"" strString = strString.stringByReplacingOccurrencesOfString("\"", withString: "")
kmb7vmvb6#
您可以使用\从字符串中删除引号\”(双引号)'(单引号)例如:
NSString *s = @"your String"; NSCharacterSet *newStr = [NSCharacterSet characterSetWithCharactersInString:@"/""]; s = [[s componentsSeparatedByCharactersInSet: newStr] componentsJoinedByString: @""]; NSLog(@"%@", s);
6条答案
按热度按时间ippsafx71#
您只需使用
雨燕1
Swift 3和4的更新
5lwkijsr2#
nnsrf1az3#
在斯威夫特3中:
n8ghc7c14#
ryoqjall5#
//这样尝试
kmb7vmvb6#
您可以使用\从字符串中删除引号
\”(双引号)
'(单引号)
例如: