2

How can I increment numeric String value?

If it is initially "1", I want to increment it in every applicationDidEnterBackground click

1
  • 2
    Just convert to [yourString intValue] and increment and again convert to string value. Commented Mar 31, 2012 at 11:54

2 Answers 2

8

In your case it's weird that you use string for that purpose but you can technically do it like this:

int myInt = [myString intValue];// I assume you need it as an integer.
myString= [NSString stringWithFormat:@"%d",++myInt];
Sign up to request clarification or add additional context in comments.

6 Comments

If it's so hard to understand then let me make it clear: Simply to get upvoted and possibly accepted as the asnwer. I hope it's clear now.
and to become famous. :P Then you should have been given the different answer of that question which i already answered in my comments.
Ahh, sorry for violating copyright. But I guess you commented after I answered.Cheers
Ahh its ok, no need to say sorry.
hey mike, i know thats weird but, but i wanted to know the logic for that, i have just started learning that's why. . .anyways thanks for the support.
|
1

Best option: make it a number instead of a string.

Other option: strValue = [NSString stringWithFormat:@"%d", [strValue integerValue] + 1];

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.