1

I'm trying to read this but unable to get proper value.

NSString *arr = [self.myArray valueForKey:@"description"];
NSLog(@"%@",arr);

I'm getting this output :

(
        (
        050,
        051
    )
)

And also it should remove first 0 i.e 050->50

But I want it as single array, like this [50, 51]

I'm newbie, please help me out.

3 Answers3

0

Use this code

NSArray * NewArray = [[self.myArray valueForKey:@"description"]objectAtIndex: 0];
NSLog(@"New Array is %@", NewArray);
Abhinandan Pratap
  • 2,142
  • 1
  • 18
  • 39
0

Try the below code:

NSArray *arr = [[self.myArray valueForKey:@"description"]objectAtIndex: 0];
NSLog(@"%@",arr);

Also to remove the first 0 from string, You can try stringByReplacingCharactersInRange providing the place of 0.

This link can help you

Sushil Sharma
  • 2,321
  • 3
  • 29
  • 49
0

Use Below code

 [myArray setObject:arr2 forKey:@"description"];
    for (NSString *st in [[myArray valueForKey:@"description"] objectAtIndex:0]) {
        NSLog(@"%@",st);
        NSString *firstChar = [st substringToIndex:1];
        if ([firstChar  isEqual: @"0"]) {
            NSString *newStr = [st substringWithRange:NSMakeRange(1, [st length]-1)];
            NSLog(@"%@",newStr);
        }
    }

OutPut: 050 50 051 51

Rishi Chaurasia
  • 520
  • 4
  • 18