0

我想用 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的正确方法是什么?

4

2 回答 2

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);
于 2013-10-03T11:48:59.907 回答
0

尝试这个:

htmlString = [htmlString stringByReplacingOccurrencesOfString:@"width=\"625" withString:@"width=\"320];
于 2013-10-03T11:15:15.870 回答