In java how to get substring from a string till a character c?

前端 未结 9 667
广开言路
广开言路 2020-12-04 16:26

I have a string (which is basically a file name following a naming convention) abc.def.ghi

I would like to extract the substring before the first

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 16:43

    In java.lang.String you get some methods like indexOf(): which returns you first index of a char/string. and lstIndexOf: which returns you the last index of String/char

    From Java Doc:

      public int indexOf(int ch)
      public int indexOf(String str)
    

    Returns the index within this string of the first occurrence of the specified character.

提交回复
热议问题