User Tools

Site Tools

blog:2023-09-21_c_remove_leading_zeros_using_c



2023-09-21 C#: Remove Leading Zeros Using C#

  • The easy way
  • String s ="0000012345678901234567890".TrimStart(new Char[] { '0' } );
    // s = "12345678901234567890"

Regular Expressions

  • using System;
    using System.Text.RegularExpressions;
    
    public class HelloWorld
    {
        public static void Main(string[] args)
        {
            String _str = "0000132423423424565443546546356546454654633333a";
            Regex _removeLeadingZeroesReg = new Regex(@"^0+(?=\d)");
            Console.WriteLine(string.Format("{0} => {1}", _str, _removeLeadingZeroesReg.Replace(_str, "")));
        }
    }
    

TAGS

  • 41 person(s) visited this page until now.

Permalink blog/2023-09-21_c_remove_leading_zeros_using_c.txt · Last modified: 2023/09/21 09:08 by jethro

oeffentlich