views:

46

answers:

3
    //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

:)

A: 

maybe by using NSArray's componentsJoinedByString ?

Cheers, Krzysztof Zabłocki

Krzysztof Zabłocki
I think you miss understood me this is the line i need fixing: AllOrderItems = [NSString stringWithFormat:(@"%@%@: %@\n", AllOrderItems, ref, value)];Its not showing all the items within that string like i ask
Could you show an example
NSLog is working for you ? are you calling this method from separate thread ?
Krzysztof Zabłocki
Nslog is showing all the items on sperate lines, i wish to fill the AllOrderItems string with all the items on new lines eg \n
+1  A: 

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.

Jasarien
If you are lucky, it's nil. If you are in the context of a method, it is whatever random value is in that position in the stack frame.
JeremyP
True. I missed that.
Jasarien
A: 

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;
}
PeyloW
How ever \n isnt making a new line :/
and its not adding the ":"
Have you set the `numberOfLines` property on `orderDetails`? By default it is set to `1`, meaning exactly one row. Set it to `0` to be of unlimited size.
PeyloW