第一种:
NSString *week = @“2”;
NSString *Weekday = [self passWeek:week];
+ (NSString *)passWeek:(NSString *)week {
if ([week containsString:@"1"]) {
week = [week stringByReplacingOccurrencesOfString: @"1" withString:@"周一"];
} else if ([week containsString:@"2"]) {
week = [week stringByReplacingOccurrencesOfString:@"2" withString:@"周二"];
} else if ([week containsString:@"3"]) {
week = [week stringByReplacingOccurrencesOfString:@"3" withString:@"周三"];
} else if ([week containsString:@"4"]) {
week = [week stringByReplacingOccurrencesOfString:@"4" withString:@"周四"];
} else if ([week containsString:@"5"]) {
week = [week stringByReplacingOccurrencesOfString:@"5" withString:@"周五"];
} else if ([week containsString:@"6"]) {
week = [week stringByReplacingOccurrencesOfString:@"6" withString:@"周六"];
} else if ([week containsString:@"7"]) {
week = [week stringByReplacingOccurrencesOfString:@"7" withString:@"周日"];
}
return week;
}
第二种:
NSString *week = @“2,3,4”;
NSString *Weekday = [self passWeek:week];
+ (NSString *)passWeek:(NSString *)week {
if ([week containsString:@"1"]) {
week = [week stringByReplacingOccurrencesOfString: @"1" withString:@"周一"];
}
if ([week containsString:@"2"]) {
week = [week stringByReplacingOccurrencesOfString:@"2" withString:@"周二"];
}
if ([week containsString:@"3"]) {
week = [week stringByReplacingOccurrencesOfString:@"3" withString:@"周三"];
}
if ([week containsString:@"4"]) {
week = [week stringByReplacingOccurrencesOfString:@"4" withString:@"周四"];
}
if ([week containsString:@"5"]) {
week = [week stringByReplacingOccurrencesOfString:@"5" withString:@"周五"];
}
if ([week containsString:@"6"]) {
week = [week stringByReplacingOccurrencesOfString:@"6" withString:@"周六"];
}
if ([week containsString:@"7"]) {
week = [week stringByReplacingOccurrencesOfString:@"7" withString:@"周日"];
}
return week;
}