2013-05-16 53 views
0

在此代碼中,我在這裏發送代碼號和電話號碼seperatly,我有兩個textFiedls電話代碼號字段和電話號碼字段,但我想連接代碼號和電話號碼字段和發送它作爲完整的手機號碼...如何連接iphone中的兩個字符串

請幫我如何連接codenumber和電話號碼。

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

我非常非常新的這個計劃需要你的幫助

+0

@Sumit蒙德拉..高興地看到,你在上:) – Rajneesh071

回答

2

Here is all way you can do with string

//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:@" "]; 
+0

Rajnessh謝謝你這麼多它可以幫助我很多 –

+0

你的歡迎@ user2365547,你可以接受答案:) – Rajneesh071

+1

感謝它的工作:) :) –

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

謝謝這是工作,但當我點擊向上或向下箭頭那裏是一條消息「投票up/d自己需要125聲望「這條消息是什麼? –

+0

@ user2365547歡迎,我知道我親愛的,但在這種情況下,你可以接受這個答案 –

+0

@ZeeshanShaikh爲upvote你需要15回購和爲反對票你需要125回購:) – Rajneesh071

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

如果= AAA和b = BBB然後你將需要編寫

[a stringByAppendingString:b]; 

所以你的情況這將是[codeLbl.text stringByAppendingString:phoneNumLbl.text];

有關此方法的詳細信息,請參閱NSString Documentation

如果不幫你,請讓我知道