教程集 www.jiaochengji.com
教程集 >  脚本编程  >  java  >  正文 java学习笔记之字符串查找函数

java学习笔记之字符串查找函数

发布时间:2016-11-11   编辑:jiaochengji.com
教程集为您提供java学习笔记之字符串查找函数等资源,欢迎您收藏本站,我们将为您提供最新的java学习笔记之字符串查找函数资源
在java中查找字符与js有一点像我可以使用indexOf函数或lastindexOf函数来查找字符是否存了,具体操作方法如下图所示,希望例子能给大家带来帮助。

java中查找一个字符串是否包含一个字符,或者一段字符串java.lang.String

indexOf方法

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy1542')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy1542>

package com.java.lang;
 
public class StringX {
 
 /**
  * @param args
  */
 public static void main(String[] args) {
  java.lang.String a = "my name is yuexiaosheng,my blog is java-er.com";
     int isPos = a.indexOf("is");
     int islastPos = a.lastIndexOf("is");
 
     System.out.println("first 'is' postion is " isPos);
     System.out.println("last 'is' postion is " islastPos);
 
     int haswen = a.indexOf("?");
     System.out.println(haswen);
     if(haswen==-1){
      System.out.println("字符串中没有问号");
     }
 
 }
 
}
 int indexOf(int ch)

返回指定字符在此字符串中第一次出现处的索引。

int indexOf(int ch, int fromIndex)

从指定的索引开始搜索,返回在此字符串中第一次出现指定字符处的索引。

int indexOf(String str)

返回第一次出现的指定子字符串在此字符串中的索引。

int indexOf(String str, int fromIndex)

从指定的索引处开始,返回第一次出现的指定子字符串在此字符串中的索引。

String intern()

返回字符串对象的规范化表示形式。

int lastIndexOf(int ch)

返回最后一次出现的指定字符在此字符串中的索引。

int lastIndexOf(int ch, int fromIndex)

从指定的索引处开始进行后向搜索,返回最后一次出现的指定字符在此字符串中的索引。

int lastIndexOf(String str)

返回在此字符串中最右边出现的指定子字符串的索引。

int lastIndexOf(String str, int fromIndex)

从指定的索引处开始向后搜索,返回在此字符串中最后一次出现的指定子字符串的索引。

int length()

返回此字符串的长度。

您可能感兴趣的文章:
java学习笔记之字符串查找函数
php查找字符串学习笔记
想系统学习GO语言(Golang
PHP字符串处理之学习笔记
php字符串查找函数strstr()、strrchr()实例
php 字符串替换函数学习
php字符串查找函数(strrpos与strchr)
php查找字符串中http地址
SQLite3数据库操作学习笔记
php字符串函数有哪些

[关闭]
~ ~