0

当我向 Web 服务发送一些值时,我的标签会显示 Web 服务的某些字段。

StationIDLabel 显示来自网络服务的站 ID,如 12/345。但我想显示为 12345

开始元素

if ( [elementName isEqualToString:@"StationID"] ) {
    if (!retornoSOAP) {
        retornoSOAP = [[NSMutableString alloc] init];
    }
    teveRetorno = YES;
  }

didEnd 元素

  if (

    [elementName isEqualToString:@"StationID"] ) {

    StationIDLabel.text = retornoSOAP;
    retornoSOAP = nil;
    teveRetorno = NO;

 }

 }
4

4 回答 4

1

尝试

if ([elementName isEqualToString:@"StationID"] ) {
    retornoSOAP = [retornoSOAP replaceOccurrencesOfString:@"/" withString:@"" options:0 range:NSMakeRange(0, retornoSOAP.length)]; 
    StationIDLabel.text = retornoSOAP;
    retornoSOAP = nil;
    teveRetorno = NO;
   }
}
于 2013-05-15T10:09:29.260 回答
1

试试这个:

NSString *myString = @"123/45";
    myString = [myString stringByReplacingOccurrencesOfString:@"/" withString:@""];

    NSLog(@"My String %@", myString);
于 2013-05-15T10:10:05.840 回答
1

你可以使用:

NSString *stringWithoutUnWantedChar = [myString 
   stringByReplacingOccurrencesOfString:@"/" withString:@""];

替换您不想要的每个字符。此代码将删除所有不需要的字符,但不会删除字符串中的数字

NSString *originalString = @"(123) 123/123 abc";
    NSMutableString *strippedString = [NSMutableString 
            stringWithCapacity:originalString.length];

    NSScanner *scanner = [NSScanner scannerWithString:originalString];
    NSCharacterSet *numbers = [NSCharacterSet 
            characterSetWithCharactersInString:@"0123456789"];

    while ([scanner isAtEnd] == NO) {
      NSString *buffer;
      if ([scanner scanCharactersFromSet:numbers intoString:&buffer]) {
        [strippedString appendString:buffer];

      } else {
        [scanner setScanLocation:([scanner scanLocation] + 1)];
      }
    }

    NSLog(@"%@", strippedString); // "123123123"
于 2013-05-15T10:10:44.530 回答
1

尝试这个:

    retornoSOAP = [retornoSOAP stringByReplacingOccurrencesOfString:@"/" withString:@""];
    //add above line

    StationIDLabel.text = retornoSOAP;
于 2013-05-15T10:11:19.420 回答