1

In Cocoa, there is a method (lineBreakBeforeIndex:withinRange:) on NSAttributedString to find appropriate line breaks in a piece of text.

Since NSAttributedString does not exist on the iPhone, does anyone have any suggestions for similar functionality?

Edit: Realized that I'm really looking for a word-wrap algorithm. For example, I want the text to wrap at 80 characters; where do I place line breaks so that words are not split over two lines?

Edit: An example will probably help. Say I have the following lines:
Here is line 1 that probably won't even be 80 characters long.
Here is another line with different text that is longer but not by much.

I would like to turn that into something like:
Here is line 1 that probably
won't even be 80 characters
long.
Here is another line with
different text that is
longer but not by much.

Edit: I'm looking to place this text in a UITextView so that additional edits can be made (very similar to a quoted reply with emails)

hjon
  • 483
  • 4
  • 10
  • Do you need to line break a string in general or specific text like UILabel by any chance? – stefanB Jun 09 '09 at 05:31
  • The string itself would be coming from an outside source; it won't be coming from (or going into) a UILabel. – hjon Jun 09 '09 at 16:03

1 Answers1

0
NSString *newString = [oldString stringByReplacingOccurrencesOfString:@"\n" withString:@"<br />"];

That will find all your line breaks and replace it with a "
" tag. Just edit it for your own needs. :)

Brandon Schlenker
  • 5,078
  • 1
  • 36
  • 58
  • Sorry, I didn't phrase the question very well. Hopefully my edit makes it more clear. – hjon Jun 09 '09 at 03:31