I made a textview that is bulleted only. It works just like a bulleted list in word. Now I am making an array using this code to separate strings by a bullet point (\u2022)
//get the text inside the textView
NSString *textContents = myTextView.text;
//make the array
NSArray *bulletedArray = [textContents componentsSeparatedByString:@"\u2022"];
//print out array
NSLog(@"%@",bulletedArray);
It works perfectly with separating the text into components by bullet points but it keeps the first line that has nothing in it. So when it prints out it looks like this.
"",
"Here is my first statement\n\n",
"Here is my second statement.\n\n",
"This is my third statement. "
The very first component of the array is “” (nothing). Is there a way to avoid adding components that equal nil?
Thanks.
Sadly, this is the way the
componentsSeparatedBy...methods ofNSStringwork:Since you know that the first element will always be empty, you can make a sub-array starting at element
1:Alternatively, you can use
substringFromIndex:to chop off the initial bullet character from the string before passing it to thecomponentsSeparatedByString:method: