gnn40036

Java 实例 - 字符串搜索

以下实例使用了 String 类的 indexOf() 方法在字符串中查找子字符串出现的位置,如果存在返回字符串出现的位置(第一位为0),如果不存在返回 -1:

SearchStringEmp.java 文件

public class SearchStringEmp {
   public static void main(String[] args) {
      String strOrig = "Google Runoob Taobao";
      int intIndex = strOrig.indexOf("Runoob");
      if(intIndex == - 1){
         System.out.println("没有找到字符串 Runoob");
      }else{
         System.out.println("Runoob 字符串位置 " + intIndex);
      }
   }
}

以上代码实例输出结果为:

Runoob 字符串位置 7

分类:

技术点:

相关文章:

  • 2021-04-19
  • 2021-09-19
  • 2021-10-14
  • 2021-12-17
  • 2021-12-24
  • 2021-09-01
  • 2021-06-15
  • 2022-01-25
猜你喜欢
  • 2022-12-23
  • 2021-12-03
  • 2021-08-26
  • 2021-11-25
  • 2021-12-03
  • 2021-12-03
  • 2021-12-03
相关资源
相似解决方案