我想用htmlstring设置UIWebView,我的图像有问题: ...
<img align="absBottom" alt="" height="350" src="http://www.xyz.com//files/userfiles/images/abc.jpg" vspace="10" width="625" />
...
我想将高度和宽度替换为200和320。 我正在使用
htmlString = [htmlString stringByReplacingOccurrencesOfString:@"width=\"" withString:@"width=\"320];
然后我得到了结果:
<img align="absBottom" alt="" height="350" src="http://www.xyz.com//files/userfiles/images/abc.jpg" vspace="10" width="320625" />
如何从htmlString中删除宽度后的数字或将宽度替换为320px的正确方法是什么?
答案 0 :(得分:1)
使用NSScanner
:
NSScanner *theScanner;
NSString *subStrng =nil;
theScanner = [NSScanner scannerWithString:htmlString];
[theScanner scanUpToString:@"width" intoString:NULL] ;
[theScanner scanUpToString:@" " intoString:&subStrng] ;
htmlString = [htmlString stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@", subStrng] withString::@"width=\"320\""];
NSLog("%@",subStrng);
答案 1 :(得分:0)
试试这个:
htmlString = [htmlString stringByReplacingOccurrencesOfString:@"width=\"625" withString:@"width=\"320];