我有一個包含多個數字的字符串,這些數字必須在同一個字符串中再次處理和替換。在字符串之間匹配多個數字,處理它們並替換
例如:
讓我們說我有:
my name is anusha, I am a noob in Java having reputation: 3647 haha I am just kidding my actual reputation is 0001
現在可以說,我想提取3647和乘除法或添加什麼東西。我們將3647/100 = 36.47分開,用0001中的原始數字替換爲0001,然後替換爲00.01。
結果字符串應該是:
my name is anusha, I am a noob in Java having reputation: 36.47 haha I am just kidding my actual reputation is 00.01
感謝你的幫助。我知道這很愚蠢,但我仍然在學習。
我試着這樣做:
Pattern intsOnly = Pattern.compile("\\d+");
Matcher makeMatch = intsOnly.matcher("my name is anusha, I am a noob in Java having reputation: 3647 haha I am just kidding my actual reputation is 0001");
makeMatch.find();
String inputInt = makeMatch.group();
System.out.println(inputInt);
但很明顯,它只能拿起第一個數字,因爲我沒有使用循環,還我真的不知道如何處理的數量。
有你試過什麼了嗎? – XtremeBaumer
請閱讀http://stackoverflow.com/help/how-to-ask。告訴我們你已經嘗試了什麼,哪些不起作用。 –
是的,明白了。在問題中加入了我的試驗。謝謝! – Anusha