0

in my app I need to search for sub strings in a very long string. This string is read from a file with multiple lines.

I want to read the substring between "(" and ")" which are often available in the string and save them to an array. Example of string:

bla bla bla ( text) bla bla bla bla (text) bla bla
bla ( text) bla bla bla bla (text) bla bla ( text )

The "text" parts are the ones I need.

What would be the most efficient way of doing this?

Thanks a lot!

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
freshking
  • 1,824
  • 18
  • 31
  • 2
    is this a homework question? – Taryn East Feb 13 '13 at 03:44
  • You can probably use `Regex.Match` with an expression like `"(.+)" to match everything between brackets (but it will include the brackets...). You will get a lot of inspiration from reading [this earlier article](http://stackoverflow.com/questions/4892452/regex-match-multiple-times-in-string) – Floris Feb 13 '13 at 03:46
  • @floris there is no "Regex.Match" in obj-c. But the asker may want to check out the `NSRegularExpression` class – nielsbot Feb 13 '13 at 04:37

1 Answers1

1

Use NSScanner Scanner and Scan up to the "(" first , then scan it, then scan up to the ")". Then get the last scan result.

Ganapathy
  • 4,594
  • 5
  • 23
  • 41