Pregunta

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];

I'm getting output as

https:google.com/images/320.png

How to remove the space in url

¿Fue útil?

Solución 2

Just do:

[str stringByReplacingOccurrencesOfString:@" " withString:@""]

Otros consejos

Try this

NSString *str = @"http://...";
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

You can trim your NSString if your space are on the sides.

NSString *trimMe = @"    Trim this string      ";
trimMe = [trimMe stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@"Trimmed String: ++%@++", trimMe);
//returnes Trimmed String: ++Trim this string+++
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top