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 6878025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:40:21+00:00 2026-05-27T04:40:21+00:00

I have three strings (a NSString , a NSMutableString , and another NSString )

  • 0

I have three strings (a NSString, a NSMutableString, and another NSString) which I need to concatenate into a mutable string, in that order, to display as the source for a UIWebView. Comming from a PHP/JavaScript/HTML background, my knowledge of concatenation is pretty much this:

var concatenatedString = string1 + string2 + string3;

I presume that sort of thing won’t work in Objective-C, so I’m wondering how to go about pulling them all together properly.

To give a bit of setting for this, the first string (NSString) is the header and canvas element of a web page, the second string (NSMutableString) is javascript from a text field that the user can define to manipulate the canvas element, and the third string (NSString) is the end tags of the web page.

Also, rather than initially creating the NSMutableString, should I just referance the UITextView.text to the get the user’s text when concatenating the whole thing, or should I pull the text from the UITextView first?

  • 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-27T04:40:21+00:00Added an answer on May 27, 2026 at 4:40 am

    The other two answers are correct in that they answer the question as you asked it. But by your description of what you want to do there is a much easier way. Use a format.

    Assuming string1 and string3 will always be the same and only string2 will change,which is what it sounds like you are doing you can write something like this.

    static NSString *formatString = @"String1Text%@String3Text";
    NSString *completeString = [NSString stringWithFormat:formatString,self.myTextFieldName.text];
    NSLog(@"%@",completeString);
    

    The %@ in the format says to insert the description of the object following the format.(The description of an NSString is the stringValue.)
    Assuming you have a UITextField named myTextFieldName, that currently contains the text ‘String2Text‘ Then this will be the output:

    ‘String1TextString2TextString3Text‘

    In this way you only create 1 instance of an NSString format for the whole class no matter how many times you call this code.

    To me it sounds like you don’t need a mutable string at all. Feel free to leave a comment if I misunderstood anything.

    Response to comment:

    I’m not sure how you are implementing ‘moves to test it out again’ but, let’s say you have a button named ‘testJavaScript’. The IBAction method connected to that button would have the first two lines in it. So each time you pushed the button it would make a new formatted NSString filled with the current contents of the textfield. Once this string was formed it could not be changed. But it won’t matter since next time it will make another.

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

Sidebar

Related Questions

I have an NSArray that contains date strings (i.e. NSString) like this: Thu, 21
I have multiple NSString Arrays that I would like to combine into a single
I have an NSString which I want to convert into an NSDecimalNumber . The
I have three string objects: NSString *firstName; NSString *lastName; NSString *fullName; The values for
Let's say I have the following three strings: (section1){stuff could be any character, i
I have the following code string three() { return three; } void mutate(string& ref)
Suppose I have a string like this: one two three four five six seven
I have two String arrays a,b. String a [] = {one,two,three}; String b []
So, I have a file called 'dummy' which contains the string: There is 100%
I have this string: \Blah \'Blah\' Blah\ . There is another string inside it.

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.