0

I have the IP-Address 123.234.1.456:1234. Is there a way to represent it in a general form of string like how it is done in other languages. for exmaple "*. *. * . * : *", so that I can replace that IP Address wth the any new IP Address. I want to replace the IP Address that is written in a file with the new IP Address, but don't know how to locate previous IP Address from file. The file has html code in which IP Address is present, and I want to replace the IP Address present in it with new one.

Currently m using this way:

    NSRange startRange = [html rangeOfString:@"http://"];
    NSRange endRange = [html rangeOfString:@"/a.json?"];
    if(startRange.location != NSNotFound && endRange.location != NSNotFound)
    {
        NSString *oldIPString = [html substringWithRange:NSMakeRange(startRange.location+startRange.length, endRange.location)];
        html = [html stringByReplacingOccurrencesOfString:oldIPString withString:ipAdressString];
    }

Please help. Thanks in advance.

user1899840
  • 543
  • 2
  • 7
  • 19
  • use components separated by "." then use components separated bt ":" – Arun Nov 14 '13 at 12:37
  • I was trying to using the NSRange to get the beginning range of string and end range of string and replacing the ip address. Just wanted a better way. @Wain – user1899840 Nov 14 '13 at 12:47

1 Answers1

1

You can locate the previous ip address using NSRegularExpression see here

Community
  • 1
  • 1
Astri
  • 575
  • 4
  • 10