gpt4 book ai didi

java 获取价格和符号

转载 作者:行者123 更新时间:2023-12-03 01:25:55 25 4
gpt4 key购买 nike

我有一个包含商品价格的字符串。在不知道货币符号的情况下,如何提取文本中的所有价格。

I got a wristwatch for $500 and i could sell it to a Nigerian for ₦13,000 or to someone in Saudi Arabia for ﷼800

我如何获取所有价格及其货币符号。

谢谢

最佳答案

货币符号有一个正则表达式字符类:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

// (incomplete) list of currency symbols, enhance from http://www.unicode.org/charts/PDF/U20A0.pdf
private static final String CURRENCY_SYMBOLS= "\\p{Sc}\u0024\u060B";

public static void main(String[] args) {
Pattern p = Pattern.compile("[" +CURRENCY_SYMBOLS + "][\\d,]+");

Matcher m = p.matcher("I got a wristwatch for $500 and i could sell it to a Nigerian for " +
"₦13,000 or to someone in Saudi Arabia for ﷼800 or Afghanistan for ؋350");

while (m.find()) {
System.out.println(m.group());
}
}
}

//Output is:
// $500
// ₦13,000
// ﷼800
// ؋350

关于java 获取价格和符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9879995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com