gpt4 book ai didi

java - 将字符替换为点

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

我希望能够从字符串的第 8 个字符开始替换为任何字符串中的点。如何才能做到这一点?

现在我有这个:

if(tempName.length() > 10)
{
name.setText(tempName.substring(0, 10));
} else {
name.setText(tempName);
}

最佳答案

   public static String ellipsize(String input, int maxLength) {
if (input == null || input.length() <= maxLength) {
return input;
}
return input.substring(0, maxLength-3) + "...";
}

此方法将给出最大长度maxLength的字符串输出。将 MaxLength-3 之后的所有字符替换为 ...

例如。最大长度=10

abc --> abc

1234567890 --> 1234567890

12345678901 --> 1234567...

关于java - 将字符替换为点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17896778/

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