prepend a string to an exisiting string

Posted on 2006-05-01
Last Modified: 2010-05-18
I am looking to prepend 10-x #s of  0's to a string if its lenth is less than 10 and has a length x.

so if I have 12345 I want to end up with 0000012345.

What a short and sweet way of doing this? :)

Question by:IUAATech
    LVL 6

    Assisted Solution

    string a = "123";
    string b = string.Format("{0:0000000000}", Convert.ToInt32(a));
    LVL 6

    Expert Comment

    if your 12345 is an integer then you don't have to Convert.ToInt32(a) in the format, but if it's a string then you will, or else the leading 0's will not come through
    LVL 85

    Accepted Solution

    LVL 6

    Expert Comment

    PadLeft is actually the way to go on this... duh! Why didn't I think of that?

    Author Comment

    thanks guys.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now