Is there a Java equivalent to Python's Easy String Splicing?

前端 未结 8 1934
轮回少年
轮回少年 2020-12-29 03:24

Ok, what I want to know is is there a way with Java to do what Python can do below...

string_sample = \"hello world\"

string_sample[:-1]
>>> \"hell         


        
8条回答
  •  失恋的感觉
    2020-12-29 04:13

    Apache commons-lang has some support for this in StringUtils:

    Gets a substring from the specified String avoiding exceptions.

    A negative start position can be used to start n characters from the end of the String

    You'll still have to use an explicit start index though.

提交回复
热议问题