0

I have any NSarray of NSString objects.

I want to extract those string which only contains character or character&numeric from it.

For example: "D6,Bombay.Hello”" is valid whereas “123456.123,56” is invalid.

Please help if anyone have idea.

PlusInfosys
  • 3,416
  • 1
  • 19
  • 33
nik
  • 1,464
  • 4
  • 18
  • 32
  • can you share the array please? – Antony Raphel Feb 03 '17 at 09:00
  • 1
    @AntonyRaphel-here is an array ( 1.1, Detais of members, holder, more than 5% of total, d up capital, Name of the Share Holders, Mr John, ABC Limited, No. of Share, 2,34,105 74.50, 14,440 04.60, 28.940, 09.21, 2013-14, 234,105 74.50, 14,440 04.60, 28940 09.21, ) – nik Feb 03 '17 at 09:05
  • Possbile duplicate, http://stackoverflow.com/questions/2753956/how-do-i-check-if-a-string-contains-another-string-in-objective-c – JingJingTao Feb 03 '17 at 09:08

2 Answers2

3

You can filter array using predicate to get only

NSPredicate *pred = [NSPredicate predicateWithBlock:^BOOL(id str, NSDictionary *unused) {
    return ([str rangeOfCharacterFromSet:[NSCharacterSet letterCharacterSet]].location != NSNotFound);
}];

NSArray *filtered = [yourArray filteredArrayUsingPredicate:pred];
Marco Pace
  • 3,820
  • 19
  • 38
PlusInfosys
  • 3,416
  • 1
  • 19
  • 33
0
if(your_str containsString:xxx){
   // do sth
}
Gxp
  • 25
  • 1
  • 6