Java 实例 - 字符串搜索

Java 教程 · 2019-02-10 07:41:24

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

SearchStringEmp.java 文件

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

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

Codercto 字符串位置 7

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

Head First Web Design

Head First Web Design

Ethan Watrall、Jeff Siarto / O’Reilly Media, Inc. / 2009-01-02 / USD 49.99

Want to know how to make your pages look beautiful, communicate your message effectively, guide visitors through your website with ease, and get everything approved by the accessibility and usability ......一起来看看 《Head First Web Design》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码