我正在使用此代码
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Call Forward Enabled"
message:[NSString stringWithFormat:@"All calls to %@ are now forwarded to voicemail.\n Condition:\n %@ ",selected_phone_numbe ,selectedOption]
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
答案 0 :(得分:1)
在显示警告之前,您可以放置此代码,您可以一次替换所有不需要的字符。
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"()"];// declare set of unwanted charecters here.
selected_phone_numbe = [[selected_phone_numbe componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];
selectedOption = [[selectedOption componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];
答案 1 :(得分:1)
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Call Forward Enabled"
message:[NSString stringWithFormat:@"All calls to %@ are now forwarded to voicemail.\n Condition:\n %@ ",[[selected_phone_numbe stringByReplacingOccurrencesOfString:@"(" withString:@""] stringByReplacingOccurrencesOfString:@")" withString:@""] ,[[selectedOption stringByReplacingOccurrencesOfString:@"(" withString:@""] stringByReplacingOccurrencesOfString:@")" withString:@""]]
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[alertView show];
<强>输出:强>
答案 2 :(得分:0)
我认为selected_phone_numbe & selectedOption
附带该括号将其删除,然后在警报
NSCharacterSet *charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@"()"];
s = [s stringByTrimmingCharactersInSet:charsToTrim];
答案 3 :(得分:0)
selected_phone_numbe
和selectedOption
看起来是数组或字符串本身包含(和)。
检查类类型(类内省)是否为数组,使用数组[0]。
如果是字符串,那么您可以替换(
&amp;空字符串)
。
答案 4 :(得分:0)
请尝试使用这个。我希望它可以帮助你。
NSString *msgStr = [NSString stringWithFormat:@"All calls to %@ are now forwarded to voicemail.\n Condition:\n %@ ",selected_phone_numbe ,selectedOption]
msgStr = [msgStr stringByReplacingOccurrencesOfString:@"(" withString:@""];
msgStr = [msgStr stringByReplacingOccurrencesOfString:@")" withString:@""];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Call Forward Enabled"
message:msgStr delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
答案 5 :(得分:0)
试试这个:
NSString * changeString = [NSString stringWithFormat:@"All calls to %@ are now forwarded to voicemail.\n Condition:\n %@ ",[[selected_phone_numbe stringByReplacingOccurrencesOfString:@"(" withString:@""] stringByReplacingOccurrencesOfString:@")" withString:@""] ,[[selectedOption stringByReplacingOccurrencesOfString:@"(" withString:@""] stringByReplacingOccurrencesOfString:@")" withString:@""]];
UIAlertView *callAlert = [[UIAlertView alloc] initWithTitle:@"Call Forward Enabled"
message:changeString
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[callAlert show];
并检查此方法:
-(NSString *)replacingString:(NSString*)mainString removeString:(NSString *)rmString withReplace:(NSString*)rpString{
mainString = [mainString stringByReplacingOccurrencesOfString:rmString withString:rpString];
return mainString;
}
你得到了答案;
谢谢:)