Does anyone know how I can add "0" to the left side of a string? If I get "1234" I'd like to make it "012345", if I get "1234" I'd like to make it "001234". Any suggestions?
lewashby
56
Junior Poster
Recommended Answers
Jump to Poststring someString("1234"); someString.insert(0,"0");
Jump to Postdeceptikon, your method compiled just fine but didn't actually change the output of the number. If I entered 12345 it would still out put 12345 rather than 012345 which is what I'M trying to get.
Let's make something abundantly clear: the type of string matters. Are you using …
All 7 Replies
Moschops
683
Practically a Master Poster
Featured Poster
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster
lewashby
56
Junior Poster
Lucaci Andrew
140
Za s|n
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
mvmalderen
commented:
From all suggested approaches I like these the most.
+13
Moschops
683
Practically a Master Poster
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.