user393273
user393273

Reputation: 1438

Add each item into string

    //Parse this shit
//Create array of all items in order (with submatches still
NSString *myregex1 = @"\\<([a-z0-9]+)\\sref\=\"([^\"]*)\">([^\<]*)\\<\\/\\1\>";
//Get all items in an array
NSArray *items = [stringReply componentsMatchedByRegex:myregex1];
//Create string to hold all items in
NSString *AllOrderItems;

if ([items count] > 0) {

    for (NSString *item in items) {
        //NSLog(@"%d", i );
        NSString *ref = [item stringByMatching:myregex1 capture:2];
        NSString *value = [item stringByMatching:myregex1 capture:3];
        NSLog(@"Current Item: %@ : %@", ref, value);
        AllOrderItems = [NSString stringWithFormat:(@"%@%@: %@\n", AllOrderItems, ref, value)];
        OrderDetails.text = AllOrderItems;
    }
}

Im tring to get each ref & value into the string AllOrderItems so i can show it in a textView

Thanks

:)

Upvotes: 0

Views: 202

Answers (3)

Krzysztof Zabłocki
Krzysztof Zabłocki

Reputation: 1307

Maybe by using NSArray's componentsJoinedByString?

Upvotes: 0

PeyloW
PeyloW

Reputation: 36752

I think what you want is this:

//Parse this shit
//Create array of all items in order (with submatches still
NSString *myregex1 = @"\\<([a-z0-9]+)\\sref\=\"([^\"]*)\">([^\<]*)\\<\\/\\1\>";
//Get all items in an array
NSArray *items = [stringReply componentsMatchedByRegex:myregex1];
//Create string to hold all items in
NSString *allOrderItems = @"";  // Intentionally existing but empty string!

if ([items count] > 0) {
    for (NSString *item in items) {
        //NSLog(@"%d", i );
        NSString *ref = [item stringByMatching:myregex1 capture:2];
        NSString *value = [item stringByMatching:myregex1 capture:3];
        NSLog(@"Current Item: %@ : %@", ref, value);
        allOrderItems = [allOrderItems stringByAppendingFormat:(@"%@: %@\n", ref, value)];
    }
    orderDetails.text = AllOrderItems;
}

Upvotes: 0

Jasarien
Jasarien

Reputation: 58448

AllOrderItems is nil to begin with.

Then you create a new string, with the value of AllOrderItems as one of the parts, which is nil. So it assigns, nil, ref, value. Then you do that again, So you get nil, ref, value, nil, ref value. Etc etc.

Upvotes: 1

Related Questions