0

我正在使用此代码

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

我想删除警报视图中的括号

4

6 回答 6

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: @""];
于 2013-05-06T05:45:34.777 回答
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];

输出:

在此处输入图像描述

于 2013-05-06T05:46:36.797 回答
0

我认为selected_phone_numbe & selectedOption 带有该支架的将其移除,然后在警报中使用它

NSCharacterSet *charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@"()"];
s = [s stringByTrimmingCharactersInSet:charsToTrim];
于 2013-05-06T05:44:19.487 回答
0

selected_phone_numbeselectedOption查看数组字符串本身包含 ( 和 )

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

如果它是字符串,那么您可以将(&替换)为空字符串。

于 2013-05-06T05:45:16.853 回答
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];
于 2013-05-06T05:49:27.247 回答
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;

}

你得到了答案;

谢谢 :)

于 2013-05-06T06:16:18.670 回答