我想查看字符串中有多少个成功空格。它应该不超过一个。
例如:
this is ok
this is NOT ok
thisisok
this is NOT ok
答案 0 :(得分:3)
您可以测试以查看字符串中是否存在两个连续的空格,因为它还将覆盖任何长于2的空格字符串。您可以使用Contains
方法执行此操作:
string testString = "this is not OK";
if (testString.Contains(" "))
{
// Bad
}
答案 1 :(得分:0)
这应该为你提供字符串文字中继承空间的逻辑
var myRestaurant: [String] = [String]()
//Getting the data from the PFQuery class
var query = PFQuery(className: "Restaurants")
query.findObjectsInBackgroundWithBlock{
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
if let objects = objects as? [PFObject] {
for object in objects {
self.myRestaurant.append(object.objectForKey("ClassNameObject") as! String)
}
}
} else {
println("errorin fetching restaurant block")
}
}