Link to home
Start Free TrialLog in
Avatar of Jim Schwetz
Jim Schwetz

asked on

Have a C# method that will receive a List<string> of numbers, and i need to remove the leading zeros only.

Have a C# method that will receive a List<string> of numbers, and i need to remove the leading zeros only.
public List<string> RemoveLeadingZeros(List<string> commish)
        {
            List<string> lineList = new List<string>();
            int count = 0;
            foreach(string line in commish)
            {
                commish.ToString().TrimStart('0');
                
                count++;
            }
            lineList.AddRange(commish);
            return lineList.ToList();
        }

Open in new window

Data set looks like this:
0000012.74
-000001.3
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jim Schwetz
Jim Schwetz

ASKER

Thanks Chris,  all of my attempts were many lines of code,  how simple you made it, and yours worked.  Thanks
No worries Jim :)