How can I truncate my strings with a “…” if they are too long?

前端 未结 11 681
陌清茗
陌清茗 2020-12-13 23:13

Hope somebody has a good idea. I have strings like this:

abcdefg
abcde
abc

What I need is for them to be trucated to show like this if more

11条回答
  •  甜味超标
    2020-12-13 23:41

    string s = "abcdefg";
    if (s.length > 3)
    {
        s = s.substring(0,3);
    }
    

    You can use the Substring function.

提交回复
热议问题