How to return part of string before a certain character?

前端 未结 4 1337
谎友^
谎友^ 2020-12-08 18:49

If you look at the jsfiddle from question,

var str = \"Abc: Lorem ipsum sit amet\";
str = str.substring(str.indexOf(\":\") + 1);

This retur

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-08 19:23

    And note that first argument of subString is 0 based while second is one based.

    Example:

    String str= "0123456";
    String sbstr= str.substring(0,5);
    

    Output will be sbstr= 01234 and not sbstr = 012345

提交回复
热议问题