Domanda

Voglio dividere una lunga stringa ricevuta da un server a un paio di stringhe. I personaggi separati sono diversi.

Ci sono dei codice di esempio per il metodo: componentsSeparatedByCharactersInSet? Oppure posso chiedere un semplice codice per dividere "A ~ B ^ C" a "A", "B" e "C"?

È stato utile?

Soluzione

Prova questo

NSString *str = @"A~B^C";

NSArray *arr = [str componentsSeparatedByCharactersInSet:
          [NSCharacterSet characterSetWithCharactersInString:@"^~"]];

NSLog(@"%@", arr);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top