gpt4 book ai didi

java - 如何在java中转换em破折号

转载 作者:行者123 更新时间:2023-12-01 08:48:13 28 4
gpt4 key购买 nike

I have a problem, where when the end user submits the data from HTML form in a web application, they are copying the data from Word document which contains long dash or em dash.

As per the logic we are trying to read those data from database and writing it to an excel file.

As an outcome those characters are generated in the excel as shown below, which contains a kind of question mark.

  Actual output : 1993 � 1995
Expected output : 1993 – 1995

我已经在Java中完成了UTF-8编码,但在Excel中仍然得到相同的输出。怎么解决这个问题?

下面是我的代码摘录。

try {
keyStrenghts = new String(keyStrenghts.getBytes("utf-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

我使用 JDK 6 和 apache poi 来生成 Excel 文件。

最佳答案

如果仅限于破折号,这可能会解决您的问题:

keyStrenghts = keyStrenghts.replaceAll("\\p{Pd}", "-");

这是使用正则表达式将所有破折号替换为ascii“-”,如here所述。

关于java - 如何在java中转换em破折号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42549489/

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