Iphone 如何删除UIAlertView中的括号

Iphone 如何删除UIAlertView中的括号,iphone,uialertview,Iphone,Uialertview,我正在使用这个代码 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] del

我正在使用这个代码

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];

我认为
selected\u phone\u number&selectedOption
附带该括号,将其移除,然后在警报中使用

NSCharacterSet *charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@"()"];
s = [s stringByTrimmingCharactersInSet:charsToTrim];

selected\u phone\u number
selectedOption
看起来要么是数组,要么是字符串本身包含(和)

检查类类型(类内省)。如果是数组,请使用数组[0]


如果是字符串,则可以用空字符串替换
&

在显示警报之前,可以放置此代码,您可以一次替换所有不需要的字符

 NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"()"];// declare set of unwanted charecters here.

selected_phone_numbe = [[selected_phone_numbe componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];

selectedOption = [[selectedOption componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];
输出:


请尝试使用这个。我希望它能帮助你

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];
试试这个:

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;

}
你得到了你的答案

谢谢:)

-(NSString *)replacingString:(NSString*)mainString removeString:(NSString *)rmString withReplace:(NSString*)rpString{
    mainString = [mainString stringByReplacingOccurrencesOfString:rmString withString:rpString];

    return mainString;

}