-4

A typical string below 'describer' in the database looks like this

'name, year'

i.e.

'Smith, 2013'

I want to strip this by removing the comma and anything after it to be left with

'Smith'

predicate = [NSPredicate predicateWithFormat:@"describer LIKE %@", filter];
Steve
  • 15
  • 3

1 Answers1

2

You can use either of these:

1.

[describer substringToIndex:[describer rangeOfString:@", "].location];

2.

[[describer componentsSeparatedByString:@", "] objectAtIndex:0];

Both of these solutions assume that the substring you're after doesn't contain ", " string.

ayoy
  • 3,835
  • 19
  • 20
  • 1
    `componentsSeparatedByString:` never returns `nil`. It's safer to use also (it returns the whole string as the only element of an array if the string doesn't contain the comma). –  Jun 05 '13 at 17:13