0

I need to concatenate a string and a variable together - I kind of find lots of examples of adding a string prior to a variable but not the other way round - how do I do this?

 NSString *theImage = [[self.detailItem valueForKey:@" resimagefiletitle"] description], @"'add on the end";
3
  • 1
    I guess this is what you are looking for. stackoverflow.com/questions/384089/… Commented Apr 14, 2014 at 16:36
  • cheers @ungot Basa - basically I need this in reverse ie a concatenation of Variable then string - not string then variable - is that poss? Commented Apr 14, 2014 at 16:46
  • Sure it's possible. Just use [NSString stringWithFormat:@"%@ string I want added on end", variableName]. This assumes that variableName returns an NSString. Commented Apr 14, 2014 at 17:00

3 Answers 3

1

Something like this:

NSString *theImage = [NSString stringWithFormat:@"%@ %@",[self.detailItem valueForKey:@" resimagefiletitle"], @"'add on the end"];

Or:

NSString *theImage = [NSString stringWithFormat:@"%@ add on the end",[self.detailItem valueForKey:@" resimagefiletitle"]];
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

NSString *theImage = [NSString stringWithFormat:@"%@ '>",[[self.detailItem valueForKey:@"resimagefiletitle"] description]];

Here I am considering [[self.detailItem valueForKey:@"resimagefiletitle"] description] gives NSString

Comments

0

We can concat diffrent type of datatypes into string by mention the format for it.

like if your want to concat two or more strings together then you can use the following code:

NSString *NewString = [NSString stringWithFormat:@"%@%@",@"This Is",@"way to concate string"];

and if your want concat integer value then you can mention the data format for it "%i". eg: int OutOf = 150; NSString *NewString = [NSString stringWithFormat:@"%@%i",@"I got 100 out of ",OutOf];

this may help you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.