How do you remove all the alphabetic characters from a string?

后端 未结 6 1579
时光说笑
时光说笑 2020-12-24 10:18

I have a string containg alphabetic characters, for example:

  1. 254.69 meters
  2. 26.56 cm
  3. 23.36 inches
6条回答
  •  半阙折子戏
    2020-12-24 11:10

    This should work:

    // add directive at the top 
    using System.Text.RegularExpressions;
    
    string numberOnly = Regex.Replace(s, "[^0-9.]", "")
    

提交回复
热议问题