remove the first zero from a number

hi there ,

in the func i geting this kind of number 03178596
i want to dispose the zero but only if its the first digit in the num

how can i do it ?

thanks ...
Tech_MenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MogalManicCommented:
You could convert it to a number and then back to a string again:

   string numResult="03178596";
   string trimedResult=long.parse(numResult).ToString();

Or write a specialized trim function (probably faster)
public class utilClass
{
 public static string trimLeading(string s, char trimChar)
 {
    int startOffset=0;
    while(startOffset<s.Length-1) //If it is ALL 0's then leave the last one there
    {
       if (s[startOffset]!=trimChar)
         break;   //Found 1st non-trimChar
       startOffset++;
    }
      return s.SubString(startOffset);
 }
}
Then call it like this:
    string numResult="03178596";
    string trimedResult=utilClass.trimLeading(numResult, '0');

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rahul_r_jadhavCommented:
                               static void remove_zero(ref string num)
            {
                  while(num.StartsWith("0"))
                        num = num.Remove(0,1);
                  
            }
MogalManicCommented:
rahul_r_jadhav's solution is not as efficient (though quite elegant).  Each time
  num = num.Remove(0,1);
is called, a new string is created, which might slow your application down (a few seconds) with unnecessary garbage collections.
Carl TawnSystems and Integration DeveloperCommented:
Simply casting it to a numeric data type should drop any leading zeros:

i.e.

        string num = "0123456789";
        long lnum = long.Parse(num);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.