我让用户检查某些短语以构建电子邮件。这些短语用逗号分隔,但我需要将这些短语设为小写,除非它以I或I开头。除非短语开始“It”,否则它的效果很好。这句话仍然是大写的。我需要它是小写的。
CODE
NSString string = [NSString stringWithFormat:@"%@, ",boxesChecked[idx]];
// strings are in an array
[boxesChecked enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if (idx == 0) { //first string
if ([string rangeOfString:@"I'm"].location != NSNotFound) {
// leave uppercase
} else if ([string rangeOfString:@"It"].location != NSNotFound) {
string = [string stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:[[string substringToIndex:1] lowercaseString]];
} else if ([string hasPrefix:@"I"]) {
// do nothing
} else {
string = [string stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:[[string substringToIndex:1] lowercaseString]];
}
}
答案 0 :(得分:1)
您可以使用此命令将字符串更改为lowe case
NSString * myString = @" Hello,World!&#34 ;; NSString * lower = [myString lowercaseString ]; //这将是"你好,世界!"