String的substring()的用法总结

String的substring()的用法总结

    substring() 方法返回字符串的子字符串。
    1.public String substring(int beginIndex)  :截取 索引位置beginIndex(包括)  到 字符串最后

    2.public String substring(int beginIndex, int endIndex)  :截取 索引位置beginIndex(包括)  到 索引位置endIndex (不包括)

  参数
    beginIndex -- 起始索引(包括)。

    endIndex -- 结束索引(不包括)。

  返回值
    子字符串。
 实例
public class Test {
    public static void main(String args[]) {
    	String Str = new String("www.51gjie.com");

    	System.out.print("返回值 :" );
    	System.out.println(Str.substring(4) );

    	System.out.print("返回值 :" );
    	System.out.println(Str.substring(4, 6) );
	}
}

语法是:INSTR (string , substring [, position [, occurrence ] ])

INSTR函数可以得到子字符串(当然包含单个字符)在字符串中的位置,返回的是数字。 有的话就会返回大于0的数

这个位置是从1开始的,和substr 从0开始有些区别

1)得到字母“o”在FIRST_NAME字段第一次出现的位置
sec@ora10g> select FIRST_NAME, instr(FIRST_NAME,‘o’) instr from t;

FIRST_NAME INSTR

Secooler 4
2)从字符串的第5个字符开始查找,第一次出现字母“o”的位置
sec@ora10g> select FIRST_NAME, instr(FIRST_NAME,‘o’,5) instr from t;

FIRST_NAME INSTR

Secooler 5

3)从字符串的第1个字符开始查找,第二次出现字母“o”的位置
sec@ora10g> select FIRST_NAME, instr(FIRST_NAME,‘o’,1,2) instr from t;

FIRST_NAME INSTR

Secooler 5
posted @ 2021-01-23 10:03  triumph丶xs  阅读(3121)  评论(0编辑  收藏  举报