Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 991783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:09:48+00:00 2026-05-16T06:09:48+00:00

OK, after much research, and help with stackoverflow users, I’ve narrowed down how to

  • 0

OK, after much research, and help with stackoverflow users, I’ve narrowed down how to fix my problem. Most special characters work, except the ampersand.

So, how can I implement the following code twice? I want to do this

[[tvQ.text stringByReplacingOccurrencesOfString:@"&" withString:@"and"] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]

and

[[tvQ.text stringByReplacingOccurrencesOfString:@"\n" withString:@" "] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]

for the same NSString

- (void) doPost:(NSString *)sport {
NSUserDefaults *p = [NSUserDefaults standardUserDefaults];

NSString* string1 = [[p valueForKey:@"user"] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSString* string2 = [[p valueForKey:@"pass"] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSString* string3 = [[[tvQ.text stringByReplacingOccurrencesOfString:@"\n" withString:@" "] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSString* string4 = [[tvQ.text stringByReplacingOccurrencesOfString:@"&" withString:@"and"] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSString* urlString = [NSString stringWithFormat:@"http://website.com/phpscript.php?user=%@&pass=%@&cat=%@&sub=%@&body=%@",string1,string2,sport,@"",string3,string4];
id val1 = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
[p setObject:val1 forKey:@"q"];

I’m not sure what I’m doing wrong here so that it respects both arguments defined in string 3 and string4.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:09:48+00:00Added an answer on May 16, 2026 at 6:09 am

    Just nest the method that transforms the string:

    [[[tvQ.text stringByReplacingOccurrencesOfString:@"&" withString:@"and"] stringByReplacingOccurrencesOfString:@"\n" withString:@" "] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]
    

    Now the string has all ‘&’ replaced by “and”, AND all “\n” replaced by ” “, AND it has been processed through stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding to make it safe to pass as a web query.

    But remember the problem the last question showed – don’t nest too deeply, or it can get very hard to read what you wrote when you later go back to it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After much research and trial and error I found how to store the items
After much googling and console testing I need some help with arrays in rails.
So I've decided after much debate and research to use symfony on my next
I installed PHP and MySql separately, configured IIS and php.ini, after much research I
After much research I am a little confused by which identity tracker I should
Not knowing the proper way, after much research on the web I found so
After much research, I have learned that binding the scroll event to the $(window)
After much searching and googling I am coming back to the well. I have
After much reading it seems that, really, the only way to read a number
After much fiddling, I've managed to install the right ODBC driver and have successfully

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.