Trim a string based on the string length

后端 未结 12 859
無奈伤痛
無奈伤痛 2020-12-12 14:29

I want to trim a string if the length exceeds 10 characters.

Suppose if the string length is 12 (String s=\"abcdafghijkl\"), then the new trimmed string

12条回答
  •  自闭症患者
    2020-12-12 15:26

    With Kotlin it is as simple as:

    yourString.take(10)
    

    Returns a string containing the first n characters from this string, or the entire string if this string is shorter.

    Documentation

提交回复
热议问题