【发布时间】:2013-11-14 12:29:19
【问题描述】:
我的 IP 地址是 123.234.1.456:1234。有没有办法以一般形式的字符串表示它,就像它在其他语言中的完成方式一样。例如“*。*。*。*:*”,这样我就可以用任何新的 IP 地址替换那个 IP 地址。 我想用新的 IP 地址替换文件中写入的 IP 地址,但不知道如何从文件中找到以前的 IP 地址。 该文件有 html 代码,其中存在 IP 地址,我想将其中存在的 IP 地址替换为新的。
目前m使用这种方式:
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];
}
请帮忙。 提前致谢。
【问题讨论】:
-
使用“.”分隔的组件然后使用组件分隔 bt ":"
-
我试图使用 NSRange 来获取字符串的开始范围和字符串的结束范围并替换 IP 地址。只是想要一个更好的方法。 @Wain
标签: ios objective-c replace nsstring