Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 852
  • Last Modified:

prepend a string to an exisiting string

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? :)

Thanks.
0
IUAATech
Asked:
IUAATech
  • 3
2 Solutions
 
PoeticAudioCommented:
string a = "123";
string b = string.Format("{0:0000000000}", Convert.ToInt32(a));
0
 
PoeticAudioCommented:
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
0
 
PoeticAudioCommented:
PadLeft is actually the way to go on this... duh! Why didn't I think of that?
0
 
IUAATechAuthor Commented:
thanks guys.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now