indexOf Case Sensitive?

后端 未结 19 1278
日久生厌
日久生厌 2020-11-27 19:39

Is the indexOf(String) method case sensitive? If so, is there a case insensitive version of it?

19条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 20:00

    The indexOf() methods are all case-sensitive. You can make them (roughly, in a broken way, but working for plenty of cases) case-insensitive by converting your strings to upper/lower case beforehand:

    s1 = s1.toLowerCase(Locale.US);
    s2 = s2.toLowerCase(Locale.US);
    s1.indexOf(s2);
    

提交回复
热议问题