2

I have a number of strings like these. The numbers can be infinitely long.

<a href="?page=1">1</a>
<a href="?page=13">13</a>
<a href="?page=13121">13121</a>
<a href="?page=1389988797">1389988797</a>

What is the quickest and most code efficient way to pull JUST the number from these NSStrings?

Ethan Allen
  • 14,425
  • 24
  • 101
  • 194

1 Answers1

2

Well, there are 21 non-number characters in each of your examples, so the length of the numbers will be:

NSUInteger length = (string.length-21)/2;

the location will be:

NSUInteger location = string.length-4-length;

so a quick path to the digits should therefore be:

[string substringWithRange:NSMakeRange(location, length)];
danh
  • 62,181
  • 10
  • 95
  • 136