0

在此代码中,我分别发送代码号码和电话号码,我有两个 textFiedls 电话号码字段和电话号码字段,但我想连接代码号码和电话号码字段并将其作为完整的手机号码发送...

请帮助我如何连接代码和电话号码。

self.operatorLbl.text = self.operatorStr;

    self.codeLbl.text = self.codeStr;

    self.phoneNumLbl.text = self.phoneNumStr;

    self.balanceLbl.text = self.balanceStr;

[post orderConfirm: self.operatorLbl.text :self.codeNumLbl.tex :self.phoneNumLbl.text :self.balanceLbl.text];

我是这个程序的新手,需要你的帮助

4

3 回答 3

2

这是你可以用字符串做的所有方法

//1st Way
NSString *finalString = [NSString stringWithFormat:@"%@ %@",firstString,secondString];

//2nd Way
NSString *finalString = [firstString stringByAppendingFormat:@" %@",secondString];

//3rd way
NSArray *ary= [NSArray arrayWithObjects:firstString,secondString, nil];
NSString *finalString= [ary componentsJoinedByString:@" "];
于 2013-05-16T05:26:05.253 回答
1

你可以像这样以不同的方式追加......

第一种方式

NSString *combinedStr = [NSString stringWithFormat:@"%@ %@", firstStr, secondStr];

第二种方式

对于不可变字符串

NSString *firstStr = @"FirstString";
NSString *secondStr = @"SecondString";
NSString *concatinatedString = [firstStr stringByAppendingString:secondStr];

对于可变字符串:

NSMutableString *firstStr = [NSMutableString stringWithString:@"FirstString"];
NSString *secondStr = @"SecondString";
[firstStr appendString:secondStr];
于 2013-05-16T05:30:53.637 回答
1

你可以试试这个

    NSString *string1, *string2, *result;

string1 = @"This is ";
string2 = @"my string.";

result = [result stringByAppendingString:string1];
result = [result stringByAppendingString:string2];
OR

result = [result stringByAppendingString:@"This is "];
result = [result stringByAppendingString:@"my string."];

如果 a = AAA 和 b = BBB 那么你需要写

[a stringByAppendingString:b];

所以在你的情况下[codeLbl.text stringByAppendingString:phoneNumLbl.text];

有关此方法的更多信息,请参阅 NSString 文档

如果它对您没有帮助,请告诉我

于 2013-05-16T06:12:58.930 回答