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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:54:40+00:00 2026-05-23T05:54:40+00:00

this is hard to describe but I am currently catching a string from a

  • 0

this is hard to describe but I am currently catching a string from a database, this string can be 1-4 characters long, however I am wanting to always display 4 characters, so if i get say a string back that is 34, i want it to be 0034.

I have set up a method to catch the string so now I just need to figure out how to do this. what I then plan to do is feed that string into a NSArray so I can send each [i’th] of the array off to 4 differetn methods that control animations in my app.

The reason its in string format is because I have had to bounce it round from hex, to int to string for various formatting reasons within the application.

this is my code i have so far. Suggestions/solutions would be great thankyou, I am so new its hard to find solutions for stuff like string manipulation etc..

//... other method I am getting the string from/.
[self formatMyNumber:dataString];
///..


-(void)formatMyNumber:(NSString *)numberString{
    //resultLabel.text = numberString; //check to make sure  string makes it to here.
    //NSLog(@"hello From formatMyNumber method"); //check
}

//..
//the with send off each character to 4 animation methods that accept integers.
- (void)playAnimationToNumber:(int)number{
//...

//UpDated… weird stuff happening.
here is my method so far.

//Number Formatter
-(void)formatMyNumber:(NSString *)numberString{


    NSLog(@"This is what is passed into the method%@",numberString);
    int tempInt = (int)numberString;
    NSLog(@"This is after I cast the string to an int %i",tempInt);

    //[NSString alloc] stringWithFormat:@"%04d", numberString];
    NSString *tempString = [[NSString alloc] initWithFormat:@"%04d", tempInt];

    NSLog(@"This is after I try to put zeros infront %@",tempString);

    //resultLabel.text = tempString;
    //NSLog(@"hello From formatMyNumber method");
}

this is the output.

[Session started at 2011-06-19
16:18:45 +1200.] 2011-06-19
16:18:54.615 nissanCode0.1[4298:207]
731 2011-06-19 16:18:54.616
nissanCode0.1[4298:207] 79043536
2011-06-19 16:18:54.617
nissanCode0.1[4298:207] 79043536
2011-06-19 16:18:54.617
nissanCode0.1[4298:207] hello From
formatMyNumber method

  • 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-23T05:54:41+00:00Added an answer on May 23, 2026 at 5:54 am

    As far as the number of zeros preceding your string goes there are a couple of ways to do this. I’d suggest:

    NSString *myString = [NSString stringWithFormat:@”%04d”,[dataString intValue]];

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

Sidebar

Related Questions

This shouldn't be so hard but I just can't seem to get this to
This may not really sound hard to do but it is currently killing me.
This is hard to describe, but I'll try my best. I am making a
Maybe I'm just thinking about this too hard, but I'm having a problem figuring
This might be a little hard to explain, but I will try. I want
This is going to be hard to explain but I'll try my best. I
This is something that I always find a bit hard to explain to others:
Yeah, kinda dumb title, but I found it hard to describe my problem. I
I'm sorry for ambiguous title, but this question is hard for me to put
in my Java code I have this snippet: String str = \\u9601; But I

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.