Correct URL encoding in Cocoa (ObjC) [duplicate] - ios

This question already has answers here:
How do I URL encode a string
(24 answers)
Closed 9 years ago.
I am trying to URL encode an NSString but I can't seem to find the proper way (I'm new to Obj C). I have been searching around but can't find a decent answer. So:
What is the correct, and modern, way to encode an NSString like a URL?
Thanks in advance.

Encoding to UTF-8:
NSString *strUTF8 = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

Related

How to get String from a NSTaggedPointerString? [duplicate]

This question already has answers here:
convert NSTaggedPointerString to NSString
(5 answers)
Closed 6 years ago.
It's about a Get network request, for more information please see this pic.
I want to get the argument "pilotCode", but its value is "0xa00006e....", I want to get its real value which is "admin", please tell me what should I do?
Thank you very much.
I solved this problem just now.
just add this code:
"NSString *realStr = [NSString stringWithString:pilotCode];"

Convert Arabic NSString to Decode string in IOS [duplicate]

This question already has answers here:
How do I URL encode a string
(24 answers)
Closed 8 years ago.
How to convert the Arabic text like http://www.someurl.com/Category/صفوف to http://www.someurl.com/Category/%D8%B5%D9%81%D9%88%D9%81 , Like when we paste the http://www.someurl.com/Category/صفوف to any browser it will show http://www.someurl.com/Category/%D8%B5%D9%81%D9%88%D9%81.
many solutions available
try this page first solution and solution no (17) they've what you're looking 4
How do I URL encode a string

Punctuation and return (statements?) in text field? [duplicate]

This question already has answers here:
Is it possible to include a quotation mark as part of an nsstring?
(7 answers)
Closed 9 years ago.
This is really difficult to describe as I don't know what the proper term is here, but I have written a simple self.textfield.text=#"text" line, but **
how can I use punctuation like double-quotes (") without Xcode
thinking its actual code rather than text
** (I think I have an idea but I don't know the syntax).
And **
is it also possible to add returns or enters when setting text like
this?
I am a Java programmer and can do this in that language, but I'm new to app development!
Any Demo/Example will be very much helpful for me.
** Thanks for the help,
The way to do it is to add escape characters:
NSString *string = #"This is a quote: \"To err is human\"";
NSString *string = #"This is a tab:\tTo err is human";
NSString *string = #"This is a newline:\n"To err is human\"";

How can I get a NSString between two strings in Objective-C on iOS? [duplicate]

This question already has answers here:
Remove HTML Tags from an NSString on the iPhone
(22 answers)
Closed 9 years ago.
I have this NSString:
<title>My Friends Website</title>
How do I pull out My Friends Website into it's own NSString on iOS with Objective-C?
try that:
NSString *myString = [[#"<title>My Friends Website</title>" stringByReplacingOccurrencesOfString:#"<title>" withString:#""] stringByReplacingOccurrencesOfString:#"</title>" withString:#""]];

ios when building a string I need to reuse the same placeholder [duplicate]

This question already has answers here:
Is there a way to specify argument position/index in NSString stringWithFormat?
(3 answers)
Closed 9 years ago.
I am making a string that is being used in a SQL statement. I need to reuse the same string within it several times. This string is the text from a textbox.
Current Code:
NSString *searchStr = [NSString stringWithFormat:#"(Name LIKE \'%%%#%%\' OR Contact LIKE \'%%%#%%\')", [self.txtfSearch text], [self.txtfSearch text]];
All the %'s are for a contains search. Please no comments on this method as I am connecting to a webservice that I have no control over currently. Im sure you can all relate.
What I need to do is reuse the [self.txtfSearch text] part at the end. I have looked up the apple dev docs on strings and placeholders. I even tried the C# method of using {0} for the placeholder but I cant get it working.
Doing it as above isnt a big deal if im looking in 2 columns, but there are many cases where its going to be 6 or more and then the string building gets ridiculous.
I want something like this:
NSString *searchStr = [NSString stringWithFormat:#"(Name LIKE \'%%{0}%%\' OR Contact LIKE \'%%{0}%%\')", [self.txtfSearch text]];
Is there a way to do this in obj-c?
Could you do something like this:
NSString *placeholderStr = #"_";
NSString *searchStr = [#"(Name LIKE '%%_%%' OR Contact LIKE '%%_%%'" stringByReplacingOccurrencesOfString: placeholderStr withString: [self.txtfSearch text]];
This will replace all of the underscores (_) with whatever text is in txtfSearch.

Resources