如何编辑标签

时间:2013-05-15 10:01:46

标签: ios soap uilabel

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

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

didStartElement

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

didEndElement

  if (

    [elementName isEqualToString:@"StationID"] ) {

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

 }

 }

4 个答案:

答案 0 :(得分:1)

尝试

if ([elementName isEqualToString:@"StationID"] ) {
    retornoSOAP = [retornoSOAP replaceOccurrencesOfString:@"/" withString:@"" options:0 range:NSMakeRange(0, retornoSOAP.length)]; 
    StationIDLabel.text = retornoSOAP;
    retornoSOAP = nil;
    teveRetorno = NO;
   }
}

答案 1 :(得分:1)

试试这个:

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

    NSLog(@"My String %@", myString);

答案 2 :(得分: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"

答案 3 :(得分:1)

试试这个:

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

    StationIDLabel.text = retornoSOAP;