當前位置:首頁 » 編程語言 » java取數

java取數

發布時間: 2023-03-06 16:24:43

java如何從字元串中提取數字

使用正則表達式可以很方便地從文本中截取數字,下面是詳細代碼:
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
String phoneString = "哈哈,13888889999";
// 提取數字
// 1
Pattern pattern = Pattern.compile("[^0-9]");
Matcher matcher = pattern.matcher(phoneString);
String all = matcher.replaceAll("");
System.out.println("phone:" + all);
// 2
Pattern.compile("[^0-9]").matcher(phoneString).replaceAll("");
}
}

熱點內容
php下載的文件名是亂碼 發布:2025-10-18 13:42:47 瀏覽:916
linux啟動資料庫oracle 發布:2025-10-18 13:26:00 瀏覽:723
金字塔的密碼大概是多少 發布:2025-10-18 13:23:13 瀏覽:978
手游發布源碼 發布:2025-10-18 13:21:38 瀏覽:698
手機密碼在哪裡關掉 發布:2025-10-18 12:48:57 瀏覽:176
t3編譯 發布:2025-10-18 12:39:27 瀏覽:226
約束比例演算法 發布:2025-10-18 12:36:35 瀏覽:591
安卓哪個軟體能下土星ss游戲 發布:2025-10-18 12:36:33 瀏覽:494
ov配置低怎麼那麼貴 發布:2025-10-18 12:35:54 瀏覽:751
微信需要什麼密碼才能打開 發布:2025-10-18 12:10:23 瀏覽:624