这是我的代码:
NSString *trimfeedback = [FeedbackTxtString stringByReplacingOccurrencesOfString:@"<br><u>Your
answer</u>:<ca>#ya#</ca><br><u>Correct answer</u>:<br>" withString:@"<p>"];
要替换的字符串将是静态的,而“FeedbackTxtString”可以包含“正确答案”或“正确答案”的文本。我需要实现OR案例,因为我不知道'FeedbackTxtString'中会有什么。如果FeedbackTxtString包含“正确答案”,则要替换的字符串应为<br><u>Your answer</u>:<ca>#ya#</ca><br><u>Correct answers</u>:<br>" withString:@"<p>
,或者如果它包含“正确答案”,则要替换的字符串应为<br><u>Your answer</u>:<ca>#ya#</ca><br><u>Correct answer</u>:<br>" withString:@"<p>
我怎么能这样做?
答案 0 :(得分:1)
这样做:
if([FeedbackTxtString rangeOfString:@"Correct answers"].location != NSNotFound)
{
NSString *trimfeedback = [FeedbackTxtString stringByReplacingOccurrencesOfString:@"<br><u>Your answer</u>:<ca>#ya#</ca><br><u>Correct answers</u>:<br>" withString:@"<p>"];
}
else if([FeedbackTxtString rangeOfString:@"Correct answer"].location != NSNotFound)
{
NSString *trimfeedback = [FeedbackTxtString stringByReplacingOccurrencesOfString:@"<br><u>Your answer</u>:<ca>#ya#</ca><br><u>Correct answer</u>:<br>" withString:@"<p>"];
}