0

这是我的代码:

 NSString *trimfeedback = [FeedbackTxtString stringByReplacingOccurrencesOfString:@"<br><u>Your 
 answer</u>:<ca>#ya#</ca><br><u>Correct answer</u>:<br>" withString:@"<p>"];

要替换的字符串将是静态的,并且 'FeedbackTxtString' 可以包含文本 'Correct answer' 或 'Correct answers' 。我需要实现 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> 我该怎么做?

4

1 回答 1

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>"];
  }
于 2012-05-24T11:19:47.413 回答