0

i have some text which is separated by space@" ".i displayed this array from DB named delegate.allSelectedVerseEnglish (array name) to a textview in the below formate.

self.multiPageView.text=[delegate.allSelectedVerseEnglish componentsJoinedByString:@" "];

multipageview is the textview,my need is to put numbers between these space.means i have 3 text which is separated by space for e.g.: my name is icoder my old is twenty my passion is coding etc etc,i need to set this text to 1 my name is icoder 2 my old is twenty 3 my passion is coding etc etc,how can i appen like this.i already got the text correctly but need in this formate.the DB does not have the numbers,i have to put numbers between separate text.

is anyone have the idea how to implement this..i hope you understand my question. thanks in advance.

1 Answer 1

1

Updated: I have rewritten this to use an NSMutableString as this won't hammer the autorelease pool like my original version.

NSMutableString *combined = [NSMutableString string];
for(NSUInteger idx = 0; idx < [delegate.allSelectedVerseEnglish count]; idx++) {
    [combined appendFormat:@" %d %@", 
                            idx + 1, 
                            [delegate.allSelectedVerseEnglish objectAtIndex:idx]];
}

self.multiPageView.text = combined;
Sign up to request clarification or add additional context in comments.

7 Comments

i put your code,but getting this warning in second line combined = [combined stringByAppendingFormat:@" %d %@", idx, [// here i get the warning delegate.allSelectedVerseEnglish ObjectAtIndex:idx]]; instance method-objectatindex not found( retune type default to id)
ObjectAtIndex should have a lower-case o
I've fixed the ObjectAtIndex typo.
@Jenox - I was about to rewrite this to use an NSMutableString as this version will hammer the autorelease pool depending on how many items are in the array.
@mttrb agin the app crashes ,the log says"Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 31 beyond bounds [0 .. 30]' "
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.