shreedevi
shreedevi

Reputation: 539

Display data of NSMutable String in table View

i am accessing web services, which give me result in string array. Say if the length of string array is 3, The first string is "1|123|Bank Of America|111|recall" (| is a delimiter) The second String is "2|456|JP Morgan|22|recall" The Third String is "3|1789|Amex|333|recall"

Now when i parse the SOAP web services, the result is in a NSMutable String. For the First string value , The Value of Mutable String is "1|123|Bank Of America|111|recall" Second time when the parser encounters the return tag, the value of MutableString is "1|123|Bank Of America|111|recall2|456|JP Morgan|22|recall" And Third Time it becomes "1|123|Bank Of America|111|recall2|456|JP Morgan|22|recall3|1789|Amex|333|recall"

I want to display the 3 strings , by removing the delimiter ("|") in a table View, how am i to do it.

Upvotes: 0

Views: 333

Answers (2)

luvieere
luvieere

Reputation: 37494

Use [yourMutableString componentsSeparatedByString: @"|recall"] to obtain an array of your three strings if you store them all concatenated. Then, take each component and split it by the @"|" string: [eachComponent componentsSeparatedByString: @"|"], and display the resulting substrings in UILabels addes as children of each UITableViewCell's contentView.

Here's a video tutorial on working with UITableView.

Upvotes: 0

Vladimir
Vladimir

Reputation: 170839

If you want just to change "|" symbol to another then you can use NSMutableString's method:

- (NSUInteger)replaceOccurrencesOfString:(NSString *)target withString:(NSString *)replacement options:(NSStringCompareOptions)opts range:(NSRange)searchRange

You can also obtain an array of the parts of your string separated with "|" using either NSString's -componentsSeparatedByString or -componentsSeparatedByCharactersInSet methods

Upvotes: 1

Related Questions