Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

I have a situation here. Consider that the system grab a data from database; 0002506 and I want to remove the 0 until it find a number larger than 0 to be save. And the result, the final data will be 2506. Any of you have an idea how to solve this? I'm using visual studio 2010.
Posted
Comments
Sergey Alexandrovich Kryukov 8-Feb-12 1:48am    
Incorrect question!
--SA

This is an incorrect question.

I hope you don't store strings like "0002506" in your database, but you store data in numeric types. (If by some reason you store strings, it's wrong in first place, nothing to discuss. :-)) These types are binary, so 0002506 and 2506 are equal objects.

So, there is nothing to "remove". If you simply display/output this value using int.ToString(), it will return "2506", not "0002506".

The leading zeros and other artifacts can only appear if you explicitly specify a string format to do so. Please see:

http://msdn.microsoft.com/en-us/library/8wch342y.aspx[^],
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^].

Bad news for you: you do not know some very basic ideas of programming. Not to worry: you can learn them pretty fast. Just don't waste your time on software development fields you poorly understand but spend more time on learning, until it's too late. :-)

—SA
 
Share this answer
 
v2
Comments
Espen Harlinn 8-Feb-12 9:20am    
Good points :)
Sergey Alexandrovich Kryukov 8-Feb-12 10:41am    
Thank you, Espen.
--SA
Luiey Ichigo 28-Mar-12 0:17am    
:D Now I get it..the number that stored in database is in string type because it is not declare as amount. Just account number which contain only numeric value, not alphanumeric. But what my friend explain and some of your explanation, I just need to convert the string to integer IF I use the number for check digit.. This is the requirement to save the data to database. It must contain 7 digit and include 0 where the account number start with 1 and from database it will format it to 0000001..TQ for your explanation :)
Sergey Alexandrovich Kryukov 28-Mar-12 10:40am    
You are very welcome.
Good luck, call again.
--SA
If you are getting use "0002506" string from databse, use CInt("0002506"), that's it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900