當前位置:首頁 » 編程語言 » 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("");
}
}

熱點內容
超級訪問羅大佑 發布:2025-07-11 07:43:33 瀏覽:386
邁騰有什麼安全配置 發布:2025-07-11 07:42:40 瀏覽:644
c語言字元逆序 發布:2025-07-11 07:41:57 瀏覽:923
怎麼配置交換機的console密碼 發布:2025-07-11 07:41:57 瀏覽:4
東芝存儲卡視頻 發布:2025-07-11 07:41:55 瀏覽:541
cs16為什麼搜不到區域網伺服器 發布:2025-07-11 07:41:21 瀏覽:913
php項目如何上傳伺服器 發布:2025-07-11 07:35:35 瀏覽:182
壓縮機4井 發布:2025-07-11 07:34:57 瀏覽:726
win7訪問共享 發布:2025-07-11 07:34:48 瀏覽:279
telnetlinux退出 發布:2025-07-11 07:29:46 瀏覽:791