Raj
Raj

Reputation: 1213

Set newline and paragraph in string with objective C

When i parse the jason url i got string with character \n \r ... Now i want break the line where with "\n" and put the paragraph with "\r".

i got string like this.

description = "Black Chasm Cavern was designated a National Natural Landmark by the National Park Service in 1976 after being recommended by local members of the National Speleological Society, and as such is considered a \"nationally significant natural area.\U201d\n\nVisitors to the cave are enchanted by the beauty of a wide variety of formations including stalactites, stalagmites, flowstones and the vast arrays of rare helictite crystals, for which Black Chasm is justly famous.\n\nThe 45-minute walk tour follows a series of platforms, stairs and walkways designed to give the best views of the cave without compromising the naturally pristine environment. Currently, the tour culminates in a visit to the Landmark Room, the location of the greatest collections of sparkling helictite crystals.\n\nAbove ground, kids love our gemstone mining at our mining flumes right outside the Visitors Center. Everyone is guaranteed to find some real gemstones; the perfect start to a rock collection! Try our new incredibly popular geode cracking too!";

and i want to display this string in label as per format.

how can i do this job if any one have any idea please tell me ...

Thanks.

Upvotes: 2

Views: 981

Answers (1)

garyamorris
garyamorris

Reputation: 2617

I would suggest iterating through your string, separating it into an array of lines and paragraphs. Like the following.

NSArray *lines = [string componentsSeparatedByString:@"\n"];
for(NSString *line in lines)
{
NSArray *lineElements = [line componentsSeparatedByString:@"\r"];
// do something with lineElements
}

Upvotes: 1

Related Questions