我用它来填写 UILabel:
storeName.text = [self.receivedLocation.name stringByReplacingOccurrencesOfString:@"Store" withString:@""];
但这会导致在标签的开始左侧插入一个明显的空间。我该如何解决?
如果你的字符串有一个值,Store some more stuff
那么结果将是some more stuff
前导空格仍然存在。
尝试这个:
// Get original text
NSString *label = self.receivedLocation.name;
// Remove occurrences of "Store"
label = [label stringByReplacingOccurrencesOfString:@"Store" withString:@""];
// Trim any leading and/or trailing whitespace
label = [label stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
storeName.text = label;