-2

I'm wanting to create an app for iOS. In this app you input multiple commands into the input text view name myTextView. Then when you click generate all of those commands are then turned into one long command. So basically i need a way to separate the input text into an array. The string will be separated when there is a line break. This way I can put things like brackets and other things into the string. For example if I input:

say hi
say bye

that would be one string but would be turned into [say hi,time:10s] [say bye,time:10s]

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • See http://stackoverflow.com/questions/10370516/how-to-split-newline-from-nsstring-in-objectivec – rmaddy Jan 20 '16 at 16:39

2 Answers2

1

Try this?

NSArray *commands = [inputString componentsSeparatedByString:@"\n"];
arrteme
  • 393
  • 1
  • 3
  • 14
0

Please refer to the documentation of NSString here

And you will find this useful method:

 - (NSArray<NSString *> *)componentsSeparatedByString:(NSString *)separator

This method will return an NSArray of strings separated by input NSString which you will pass the @"\n".

Coldsteel48
  • 3,482
  • 4
  • 26
  • 43
  • Thanks! but i managed to solve it by using this method: let fullName: String = myTextView.text; let fullNameArr = fullName.componentsSeparatedByString("\n") let i = fullNameArr.count var c = 0 while c < i && i != 0 { OutputView.hidden = false; OutputView.text = OutputView.text + fullNameArr[c] c = i + 1 – Matthew Anderson Jan 20 '16 at 16:50