Remove leading digits from a string

后端 未结 2 1370
盖世英雄少女心
盖世英雄少女心 2021-01-25 16:47

How can I remove all the digits from the start of a string.

Before:

234234adsf3fs3fs34

After:

adsf3fs3fs34
相关标签:
2条回答
  • 2021-01-25 17:18

    You can use -Replace, which does accept RegEx:

    "234234adsf3fs3fs34" -replace "^[0-9]*"
    

    That will result in your desired output.

    Alternatively you can use the .TrimStart() method as such:

    ("234234adsf3fs3fs34").TrimStart("0123456789")
    

    That will also output what you want. It looks for anything contained within the () to remove, but is not RegEx friendly.

    0 讨论(0)
  • 2021-01-25 17:24

    Try this statement:

    string.TrimStart("1234567890")
    

    Hope that helps!

    0 讨论(0)
提交回复
热议问题