mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
StrUtil.replace歧义,修改为replaceByCodePoint
This commit is contained in:
@@ -25,7 +25,7 @@ public class CharSequenceUtilTest {
|
||||
@Test
|
||||
public void replaceByStrTest() {
|
||||
String replace = "SSM15930297701BeryAllen";
|
||||
String result = CharSequenceUtil.replace(replace, 5, 12, "***");
|
||||
String result = CharSequenceUtil.replaceByCodePoint(replace, 5, 12, "***");
|
||||
Assert.assertEquals("SSM15***01BeryAllen", result);
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,15 @@
|
||||
package cn.hutool.core.text;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IssueI96LWHTest {
|
||||
@Test
|
||||
public void replaceTest() {
|
||||
String str = "\uD83D\uDC46最上方点击蓝字";
|
||||
Console.log(str.codePoints().toArray());
|
||||
Console.log(StrUtil.replaceByCodePoint(str, 3, 4, "下"));
|
||||
Console.log(new StringBuilder(str).replace(3, 4, "下"));
|
||||
}
|
||||
}
|
@@ -1,13 +1,12 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字符串工具类单元测试
|
||||
*
|
||||
@@ -219,9 +218,9 @@ public class StrUtilTest {
|
||||
|
||||
@Test
|
||||
public void replaceTest() {
|
||||
String string = StrUtil.replace("aabbccdd", 2, 6, '*');
|
||||
String string = StrUtil.replaceByCodePoint("aabbccdd", 2, 6, '*');
|
||||
Assert.assertEquals("aa****dd", string);
|
||||
string = StrUtil.replace("aabbccdd", 2, 12, '*');
|
||||
string = StrUtil.replaceByCodePoint("aabbccdd", 2, 12, '*');
|
||||
Assert.assertEquals("aa******", string);
|
||||
}
|
||||
|
||||
@@ -251,11 +250,11 @@ public class StrUtilTest {
|
||||
@Test
|
||||
public void replaceTest5() {
|
||||
final String a = "\uD853\uDC09秀秀";
|
||||
final String result = StrUtil.replace(a, 1, a.length(), '*');
|
||||
final String result = StrUtil.replaceByCodePoint(a, 1, a.length(), '*');
|
||||
Assert.assertEquals("\uD853\uDC09**", result);
|
||||
|
||||
final String aa = "规划大师";
|
||||
final String result1 = StrUtil.replace(aa, 2, a.length(), '*');
|
||||
final String result1 = StrUtil.replaceByCodePoint(aa, 2, a.length(), '*');
|
||||
Assert.assertEquals("规划**", result1);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user