NSString* str = [inventoryDetails objectAtIndex:i];
UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(j, 10, 280, 180)];
if (![str isEqual:[NSNull null]]) {
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:[[inventoryDetails objectAtIndex:i] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
UIImage *img=[[UIImage alloc]initWithData:data];
我的输出为
的https:google.com/images/320.png
如何删除网址中的空格
答案 0 :(得分:4)
试试这个
NSString *str = @"http://...";
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
答案 1 :(得分:2)
如果你的空间位于两侧,你可以修剪你的NSString。
NSString *trimMe = @" Trim this string ";
trimMe = [trimMe stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@"Trimmed String: ++%@++", trimMe);
//returnes Trimmed String: ++Trim this string+++
答案 2 :(得分:2)
只是做:
[str stringByReplacingOccurrencesOfString:@" " withString:@""]