如何用字符串替换符替换特殊字符

时间:2019-12-27 17:59:47

标签: java string character-encoding

我有以下代码:

@Test
public void testReplace(){

    int asciiVal = 233;
    String str = new Character((char) asciiVal).toString();
    String oldName = "Fr" + str + "d" + str + "ric";
    System.out.println(oldName);

    String newName = oldName.replace("é", "_");
    System.out.println(newName);
    Assert.assertNotEquals(oldName, newName); // Its still equal. Howto Replace with a String

    String notTheWayILike = oldName.replace((char) 233 + "", "_"); // I don't want to do this.
    Assert.assertNotEquals(oldName, notTheWayILike);
}

如何用字符串替换字符? 我需要这样做,因为它们应该易于使用,定义为字符串或字符。

0 个答案:

没有答案