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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:31:27+00:00 2026-05-28T01:31:27+00:00

I can written an application which converts strings (made of numbers) from 8 –

  • 0

I can written an application which converts strings (made of numbers) from 8 – 12 characters in length (see examples below)

  • 1404336133
  • 4174728823
  • 0587035281

Basically I want to convert the strings above into a specific format (stored in a config file) for the time being its as shown below.

<add key="Consumer_Code_Format_For_Code_Length_Eight" value="#### ####"/>
<add key="Consumer_Code_Format_For_Code_Length_Nine" value="### ### ###"/>
<add key="Consumer_Code_Format_For_Code_Length_Ten" value="### #### ###"/>
<add key="Consumer_Code_Format_For_Code_Length_Eleven" value="#### ### ###"/>
<add key="Consumer_Code_Format_For_Code_Length_Twelve" value="#### #### ####"/>

I am currently using the following code to format the codes …

public static string FormatCode(string code)
{
    switch (code.Length.ToString())
    {
        case "8":
            string codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Eight"];
            code = String.Format("{0:" + codeFormat + "}", Double.Parse(code));
            break;

        case "9":
            codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Nine"];
            code = String.Format("{0:" + codeFormat + "}", Double.Parse(code));
            break;

        case "10":
            codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Ten"];
            code = String.Format("{0:" + codeFormat + "}", Double.Parse(code));
            break;

        case "11":
            codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Eleven"];
            code = String.Format("{0:" + codeFormat + "}", Double.Parse(code));
            break;

        case "12":
            codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Twelve"];
            code = String.Format("{0:" + codeFormat + "}", Double.Parse(code));
            break;

        default:
            codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Eight"];
            code = String.Format("{0:" + codeFormat + "}", Double.Parse(code));
            break;
    }

    // Finally return the newly formatted code
    return code;
}

However, for the code 0587035281 it displays “58 7035 281” therefore removing the leading zero which I require.

Any ideas how to stop this and also is there anything wrong or suspicious with my code?

Looking forward to your reply

  • 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-28T01:31:28+00:00Added an answer on May 28, 2026 at 1:31 am
    public static string FormatCode(string code)
    {
        switch (code.Length.ToString())
        {
            case "8":
                string codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Eight"];
                break;
    
            case "9":
                codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Nine"];
                break;
    
            case "10":
                codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Ten"];
                break;
    
            case "11":
                codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Eleven"];
                break;
    
            case "12":
                codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Twelve"];
                break;
    
            default:
                codeFormat = ConfigurationManager.AppSettings["Consumer_Code_Format_For_Code_Length_Eight"];
                break;
        }
    
        char[] result = new char[codeformat.Length];
    
        int used = 0;
        for(i = 0; i < codeformat.Length; i++)
        {
            if (codeformat[i] == '#')
            {
                result[i] = code[used];
                used++;
            }
            else
                result[i] = codeformat[i];
        }
        // Finally return the newly formatted code
        return new string(result);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an application from which you can write checks and I have
I have an application, currently written in C#, which can take a Base64-encoded string
I have written an application which loads information from a plist which lies on
I have written a mapping application which can either use Google Maps or Open
I have written a Ruby application which parses lots of data from sources in
I have written an application which collects windows logs from linux, via the Zenoss
Can web technologies be used for a desktop application written in a traditional language
I have a console application written in Delphi. I saw that I can have
Can someone please confirm to me that when my application is written in .NET
I've written a small console application that can perform certain tasks. The user interface

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.