indexOf
int indexOf( int x )
문자열 객체에서 x(아스키 코드 문자의 위치)가 첫번째로 발견된 위치를 반환, 없을시 -1반환
int indexOf( String x )
문자열 객체에서 str를 찾아서 존재하면 첫째문자 위치를 반환, 없을시 -1반환
lastIndexOf
int lastIndexOf( int x )
뒤에서 부터 x(아스키 코드 문자의 위치)가 첫번째로 발견된 위치를 반환
int lastIndexOf( String x )
뒤에서 부터 괄호 사이 들어간 문자의 위치를 반환
substring
String substring(x)
문자열의 x위치 부터 끝까지 문자열 추출
String substring(x,y)
x위치 부터 y위치 전까지의 위치의 문자열 추출
Char charAt(int location)
문자열 객체에서 해당위치의 문자값 1개 반환. 반환값은 char형
String testString = "Java1 Test String";
System.out.print(
"testString.indexOf(116) = " + testString.indexOf(116) + "\n" +
"testString.indexOf(\"T\") = " + testString.indexOf("T") + "\n" +
"testString.lastIndexOf(115) = " + testString.lastIndexOf(115) + "\n" +
"testString.lastIndexOf(\"T\") = " + testString.lastIndexOf("T") + "\n"
);
System.out.print(
"testString.substring(2) = " + testString.substring(2) + "\n" +
"testString.substring(0,7) = " + testString.substring(0,7) + "\n" +
"testString.charAt(6) = " + testString.charAt(6) + "\n"
);
Result
testString.indexOf(116) = 9
testString.indexOf("T") = 6
testString.lastIndexOf(115) = 8
testString.lastIndexOf("T") = 6
testString.substring(2) = va1 Test String
testString.substring(0,7) = Java1 T
testString.charAt(6) = T
indexOf 아스키 코드 문자 표
ASCII CODE
https://rockykim5581.tistory.com/22