JavaSE8基础 String indexOf 正向查找 返回字符在字符串中第一次出现时的索引值

os :windows7 x64
    jdk:jdk-8u131-windows-x64
    ide:Eclipse Oxygen Release (4.7.0)
    
    
code:

package jizuiku.t00;

public class Dome3 {
	public static void main(String[] args) {
		String str = "abc01234543210cba";
		char ch = ‘0‘;
		System.out.println(str.indexOf(ch));
	}
}

result:



Java优秀,值得学习。
学习资源:API手册+Java源码。

时间: 2024-07-30 23:54:58

JavaSE8基础 String indexOf 正向查找 返回字符在字符串中第一次出现时的索引值的相关文章

JavaSE8基础 String lastIndexOf 反向查找 返回字符在字符串中第一次出现时的索引值

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        code: package jizuiku.t00; public class Dome3 { public static void main(String[] args) { // 索引值 // 10 // 11 // 12 // 13 // 0123456789 String str = "abc01234543

JavaSE8基础 String indexOf 正向 从指定索引值开始查找 字符在字符串中第一次出现的位置

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        code: package jizuiku.t00; public class Demo4 { public static void main(String[] args) { // 索引值 0123 String str = "abc01234543210cba"; char ch = '0'; Syst

C语言strchr()函数:查找某字符在字符串中首次出现的位置

头文件:#include <string.h> strchr() 用来查找某字符在字符串中首次出现的位置,其原型为:    char * strchr (const char *str, int c); [参数]str 为要查找的字符串,c 为要查找的字符. strchr() 将会找出 str 字符串中第一次出现的字符 c 的地址,然后将该地址返回. 注意:字符串 str 的结束标志 NUL 也会被纳入检索范围,所以 str 的组后一个字符也可以被定位. [返回值]如果找到指定的字符则返回该字

JavaSE8基础 String toUpper/LowerCase 根据原字符串生成全大写小写的新字符串

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        code: package jizuiku.t01; public class Demo5 { public static void main(String[] args) { String str = "CNBLOGjizuiku"; System.out.println(str.toLowerCase(

JavaSE8基础 String getBytes 将不含中文的字符串转换成字节数组

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        code: package jizuiku.t01; import java.nio.charset.Charset; public class Demo01 { public static void main(String[] args) { String str = "[email protected]#$&qu

sqlserver 查找某个字符在字符串中第N次出现的位置

前几天的考试系统出现了一个问题,背景大概就是告诉你正确答案,比如说是:答案1#答案2#答案3...而几百个学生答题的记录也是这样格式存储的,问如何用sql语句为每个学生判分? 思路: 第一步:找到第N个#在字符串中的位置 create function fn_find(@find varchar(8000), @str varchar(8000), @n smallint)     returns int as begin     if @n < 1 return (0)     declare

BAT返回字符在字符串中的首个位置及最后一个位置

rem @echo off SETLOCAL ENABLEDELAYEDEXPANSION  set k=speed_dao_mmr_20141016_300008588738_2200125875 call :PosLastChar %k% _ aa echo %aa% pause goto :eof rem :poschar str tag Res :PosChar set SubStr= set F=0  set TmpVar=%1 set %3=-1 :pos_begin set Sub

[LeetCode] 在一堆字符串中找出包含相同字符的 group的较快方法,题 Anagrams

题目: Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case. class Solution { public: vector<string> anagrams(vector<string> &strs) { } }; 题意本身并不是很清晰,开始我的代码总是报Output Limit Exceeded,

C语言:将s所指字符串中下标为偶数同时ASCII值为奇数的字符删去,-将a所指字符串中的字符和b所指字符串中的字符的顺序交叉,-将形参s所指字符串中的所有数字字符顺序前移,

//函数fun功能:将s所指字符串中下标为偶数同时ASCII值为奇数的字符删去,s所指串中剩余的字符形成的新串放在t所指的数组中. 1 #include <stdio.h> 2 #include <string.h> 3 4 void fun(char *s, char t[]) 5 { 6 int i=0,j=0; 7 while (s[i] != '\0') 8 { 9 if (i % 2 == 0) 10 { 11 if ((int)(s[i]) % 2 == 1)//判断A