Cut Java String at a number of character

后端 未结 8 1518
我寻月下人不归
我寻月下人不归 2020-12-18 18:43

I would like to cut a Java String when this String length is > 50, and add \"...\" at the end of the string.

Example :

I have the f

8条回答
  •  再見小時候
    2020-12-18 19:00

    Something like this may be:

    String str = "abcdefghijklmnopqrtuvwxyz";
    if (str.length() > 8)
        str = str.substring(0, 8) + "...";
    

提交回复
热议问题