我有這個工作使用NSArray,直到我意識到我需要插入一個字符串數組。現在我將其更改爲NSMutableArray,但遇到了我的語法問題。我允許在NSMutable數組中使用componentsJoinedByString嗎?UITextfield問題到NSMutableArray
NSString *item;
int numofSeg;
int needSeg;
if (textfield.text == @"::") {
numofSeg = 0;
}
NSMutableArray *dlist = [[NSMutableArray alloc]init];
//take string from textfield and split it into a list on colons.
dlist = [textfield.text componentsSeparatedByString:@":"];
//run through list to count how many segments. Non blank ones.
for (item in dlist) {
if (item != @""){
numofSeg = numofSeg + 1;
NSLog(@"%@",numofSeg);
}
}
//determine number of segments
needSeg = 8 - numofSeg;
while (needSeg > 0) {
//insert 0000 at blank spot
[dlist insertString:@"0000" atIndex:@""];
needSeg = needSeg - 1;
}
for (item in dlist) {
if (item == @"") {
//remove blank spaces from list
[dlist removeAllObjects:item];
}
}
//join the list of times into a string with colon
NSString *joinstring = [dlist componentsJoinedByString:@":"];
NSLog(@"%@",joinstring);
我的主要問題是試圖在NSMutableArray中使用componentsJoinedByString。我現在有它的工作,但將其轉換回NSArray。我需要基本上在字符串@「」的索引處插入一個字符串。不在索引:0。這是我用於NSArray * item = [ipv6display.text componentsSeparatedByString:@「:」]; – Taken 2012-08-15 12:56:31
我基本上需要弄清楚如何獲取MutableArray dlist並在空白處插入sttring。 [dlist insertString:@「0000」atString:@「」] ;.在Python中,我可以這樣寫:list1.insert(list1.index(''),'0000') – Taken 2012-08-15 13:06:38
你是什麼意思「在字符串索引@」「」?你能給我一個你想要做什麼的例子嗎?你究竟遇到了什麼問題? – aforaudrey 2012-08-15 15:55:17