2011-08-17 69 views

回答

3

原始字符串:

NSString originalString = @"Hello,How are you,Norman,Stanley,Fletcher"; 

分成多行:

NSString multiLineString = [originalString stringByReplacingOccurrencesOfString:@"," withString:"@\n"]; 

分配到標籤:

label.text = mutliLineString; 

需要確保標籤需要多行:

label.numberOfLines = 0; 

將根據需要顯示多行。

+0

謝謝,但我想設置uilabel – 2011-08-17 12:17:38

+0

多個單獨的UILabels,或一個UILabel包含多行文本的分隔字符串倍數行? – jrturton 2011-08-17 12:32:03

0

你可以使用這樣的:

NSString * str = @"Hello,How are you,Norman,Stanley,Fletcher"; 

yourLabel.text = [str stringByReplacingOccurrencesOfString:@"," withString:@"\n"]); 
0

要分割你的@「你好,你是如何」使用下面的代碼:

NSString *string = @"Hello,How are you"; 
NSArray *array = [string componentsSeparatedByString: @","]; 

,並檢查是否有字符串中的逗號使用這個:

NSRange matchNotFound; 
matchNotFound = [[label text] rangeOfString: @","]; 
if ((matchNotFound.location != NSNotFound) { 
//if there is a comma 
} else { 
//if there is no comma 
} 

跳躍發現這個有用。

相關問題