given a URL like this:
http%3A%2F%2Fwww.environmental-expert.com%2FresultEachPressRelease.aspx%3Fcid%3D23745%26codi%3D234441%26lr%3D1
How can i replace the characters (like %3D and so on) to get a normal url using the iphone sdk?
thanks in advance!
Try:
NSString *myEscapedUrl = #"http%3A%2F%2Fwww.environmental-expert.com%2FresultEachPressRelease.aspx%3Fcid%3D23745%26codi%3D234441%26lr%3D1";
NSLog(#"my unescaped url: %#", [myEscapedUrl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]);
Related
Is it possible to recognize an url in xCode ?
I'm trying to create an if statement, followed by opening the url.
I can't find anything about this on the internet, I've also tried searching for recognizing the first letters (like "http, file, www");
With kind regards,
Tim
NSString class has a method rangeOfStrig:
NSString *urlString = #"http://www.someurl.com";
if ([urlString rangeOfString:#"www"].location != NSNotFound ) {
// do something
}
Use a regular expression to check for the patterns you want (www, http, https, etc)
http://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSRegularExpression_Class/Reference/Reference.html
And here is a great regex http://www.geekzilla.co.uk/view2D3B0109-C1B2-4B4E-BFFD-E8088CBC85FD.htm
And here is an example from stackoverflow, How to validate an url on the iPhone
i have string like: "YouTube - VID 0001" and i want the string like : YouTube - VID 0001 that means i want to remove the unicodes.
is there a way to remove unicodes like in iphone apps, if so please help me.
Does this similar question and solution solve your problem?
I'd also recommend heeding the advice given in the comments on the linked question and making sure that you have a valid reason for not wanting unicode.
Try this if you just want to remove the quotes (")
NSString *urString = #"\"YouTube - VID 0001\"";
NSString *formattedString = [urString stringByReplacingOccurrencesOfString:#"\"" withString:#""];
I am working on loading images into a gallery on the iPhone and running into an issue. It is apparent that something in the script isn't happy with spaces being in filename's when trying to download the images off of the internet.
This is the connection line.
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]] delegate:self];
And I pass an NSString in the NSURL. It works on all photos that don't have spaces.
Example of evil photos:
thumbs_WJ (16).jpg
thumbs_WJ (25).jpg
Now I know I could go back and update all the photos, update the database, and change the script so it doesn't add spaces anymore...but we are talking about thousands of photos.
And suggestions?
you need to do string:
str =[str stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
Use NSString's stringByAddingPercentEscapesUsingEncoding: method on the text you want to include as an argument.
From Apple docs:
stringByAddingPercentEscapesUsingEncoding:
Returns a representation of the receiver using a given encoding to determine the percent escapes necessary to convert the receiver into a legal URL string.
If your string is a "normal" string, you can use NSUTF8StringEncoding as encoding. Otherwise, specify the encoding your string is in.
Just replace spaces with "%20" in your urlstring.
i am using uiwebview in my application. there are some links when user clicks a http search starts. it works fine but i have problems while getting "%58 den ysnky'ye tepki" it is given as "X'den ysnky'ye tepki". it has problems with % char.
identifier:%58'den%20ysnky'ye%20tepki
decoded identifier:X'den ysnky'ye tepki
i am using stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding to decode the string like that;
NSLog(#"identifier:%#", identifier);
identifier = [identifier stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"decoded identifier:%#", identifier);
how can i get the correct string?
thanks...
It looks like your string may not be encoded properly in the first place. %58 is the correct encoding for the letter “X” (see this ASCII table). As far as I can tell, therefore, the decode is behaving properly.
What are you expecting?
So, what I'm trying to do, is take a .txt or html file, being able to search through it, and grab a piece of text from file, place it into a string and finally adding it into a textView.
Each couple of piece of text will be divided like this:
001:001 Text1
001:002 Text2
001:003 Text3
002:001 Text1a
002:002 Text1b
... and so on
So essentially you would search the text for those numbers, and it would grab the text only. Is there a way to do that using objective C and using it on a iPhone app?
Use
NSString *pathToDefaultPlist = [[NSBundle mainBundle] pathForResource:#"TextFile" ofType:#"text"];
to load text file. Then:
+ (id)stringWithContentsOfFile:(NSString *)path encoding:(NSStringEncoding)enc error:(NSError **)error
this function to load the text file in String. Then use NSString function to divide the token :)
In addition to the [NSString stringWithContentsOfFile:encoding:error] to get the text of the file, your textView should have a setStringValue method.
so I'd do something like this:
NSString *pathToTextFile;
NSError *readError;
NSString *fileData = [NSString stringWithContentsOfFile:pathToTextFile
encoding:(appropriate encoding for your file)
error:*readError]
[textView setStringValue:fileData];
This might need a little massaging, I'm at work and don't have my Mac to verify the method signatures etc. But that's the general idea.