>>> crazystring = ‘dade142.;!0142f[.,]ad’ 只保留數字>>> filter(str.isdigit, crazystring)‘1420142′ 只保留字母>>> filter(str.isalpha ...
最近使用python寫一腳本,就字符串中數字問題,網上查了下原來python早都為我們提供了很好的方法,在次感嘆自己python的無知,在此做下記錄 gt gt gt crazystring dade . f ., ad 只保留數字 gt gt gt filter str.isdigit, crazystring 只保留字母 gt gt gt filter str.isalpha, crazyst ...
2016-11-14 16:25 0 9314 推薦指數:
>>> crazystring = ‘dade142.;!0142f[.,]ad’ 只保留數字>>> filter(str.isdigit, crazystring)‘1420142′ 只保留字母>>> filter(str.isalpha ...
...
https://www.toutiao.com/i6938911479949181476/ ...
/// 去掉字符串中的數字 public static string RemoveNumber( string key) { return ...
替換字符串中的數字 此時得到的text為"abc". 替換字符串中的非數字 此時得到的text為"123". i表示區分大小寫。 g表示進行全局匹配。 ...
filter(lambda ch: ch in ‘0123456789.’, crazystring) ...
WRITE '數字'.ELSE. WRITE '非數字'.ENDIF. -? ...
str_1 = "123" str_2 = "Abc" str_3 = "123Abc" #用isdigit函數判斷是否數字 print(str_1.isdigit()) Ture print(str_2.isdigit()) False print(str_3.isdigit ...