Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
there are strings from a function comes...

these comes like these 01 02 03 ......09 10 11 12..... 31 strings

I want to remove zero in front of 01......09 so 01 must be 1 ,02 2, 03 3.....09 9

but 10 11 12 I will not thouch...


how to remove zero? 01 1 but 11 12 ....31 will not thouch
Posted
Comments
[no name] 7-Apr-13 16:51pm    
TrimStart can help you out.

In the format you have chosen Id go for String.Split(" ") method, and then call convert to integer and store it in a new list of integers.
 
Share this answer
 
Comments
Maciej Los 7-Apr-13 17:25pm    
Link to String.Split() method[^].

Good answer, my 5!
Kenneth Haugland 7-Apr-13 17:43pm    
Thanks :-) However I relized that he could use .StartsWith("0") also, but that would be more cumbersome.
Sergey Alexandrovich Kryukov 7-Apr-13 22:52pm    
Actually, both solutions are cumbersome compared to a better one: TrimStart; please see my answer.
—SA
The easiest way is to call myStream.TrimStart('0'); please see:
http://msdn.microsoft.com/en-us/library/system.string.trimstart.aspx[^].

However, in's important to understand that you cannot remove anything from a string, as strings are immutable. All string methods "modifying" string actually don't modify any string object, they create a brand new string with appropriate content.

—SA
 
Share this answer
 
v2
Comments
Kenneth Haugland 8-Apr-13 0:18am    
I learned something new today :-) 5'ed
Sergey Alexandrovich Kryukov 8-Apr-13 0:25am    
Thank you very much, Kenneth. (I don't think it's really new to your, just a bit of attention.)
—SA
Kenneth Haugland 8-Apr-13 0:29am    
Well, I didnt know TrimStart, the rest is just politeness :-)
Sergey Alexandrovich Kryukov 8-Apr-13 0:33am    
No, It's not about politeness. I mean, knowing each and every API is not the real knowledge which does not mean serious value. Understanding is of real value and is the real knowledge.
—SA
Kenneth Haugland 8-Apr-13 0:42am    
I actually agree with that, often I find that it is the struckturing of problem into an algorithem that is the hardest. Once that is done, its just a matter of searching or reading documentation.

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