public class StringTest {
public static void main(String[]arr) throws Exception{
String str = new String("Hello Java.txt");
char a = str.charAt(6);// 6번째 문자를 추출
System.out.println("a = " + a);
//문자열의 마지막 부분이 해당하는 문자로 끝났는지를 체크
// startWith() 는 시작 부분을 체크
boolean b = str.endsWith(".txt");
System.out.println("b = " + b);
// 대소문자 구분없이 같은지 체크 , # equals()는 대소문자 구분
boolean c = str.equalsIgnoreCase("hello java.TXT");
System.out.println("c = " + c);
// getBytes byte 배열로 리턴
// 인코딩 영문(ISO8859_1)
byte[] d = str.getBytes("ISO8859_1");
for(int i = 0; i < d.length; i++){
System.out.print(d[i] + ", ");
}
System.out.println();
// 문자로 표현시 char 로 형 변환
for(int i = 0; i < d.length; i++){
System.out.print((char)d[i] + ", ");
}
System.out.println();
// 특정 문자가 있는 위치 번째
System.out.println("o의 위치 = " + str.indexOf("o"));
// 특정 문자가 있는 위치 뒤에서 부터
System.out.println("뒤에서부터 a의 위치 = " + str.lastIndexOf("a"));
// 지정 커서 범위의 문자열 추출
System.out.println("6 ~ 10 = " + str.substring(6, 10));
// 문자열의 공백을 제거
// trim()은 화이트 캐릭터를 제거
// 화이트 캐릭터 : 1~32번, 127번 아스키 코드값을 가지는것
System.out.println(" abdieksdf d dd ".trim());
}
}
public static void main(String[]arr) throws Exception{
String str = new String("Hello Java.txt");
char a = str.charAt(6);// 6번째 문자를 추출
System.out.println("a = " + a);
//문자열의 마지막 부분이 해당하는 문자로 끝났는지를 체크
// startWith() 는 시작 부분을 체크
boolean b = str.endsWith(".txt");
System.out.println("b = " + b);
// 대소문자 구분없이 같은지 체크 , # equals()는 대소문자 구분
boolean c = str.equalsIgnoreCase("hello java.TXT");
System.out.println("c = " + c);
// getBytes byte 배열로 리턴
// 인코딩 영문(ISO8859_1)
byte[] d = str.getBytes("ISO8859_1");
for(int i = 0; i < d.length; i++){
System.out.print(d[i] + ", ");
}
System.out.println();
// 문자로 표현시 char 로 형 변환
for(int i = 0; i < d.length; i++){
System.out.print((char)d[i] + ", ");
}
System.out.println();
// 특정 문자가 있는 위치 번째
System.out.println("o의 위치 = " + str.indexOf("o"));
// 특정 문자가 있는 위치 뒤에서 부터
System.out.println("뒤에서부터 a의 위치 = " + str.lastIndexOf("a"));
// 지정 커서 범위의 문자열 추출
System.out.println("6 ~ 10 = " + str.substring(6, 10));
// 문자열의 공백을 제거
// trim()은 화이트 캐릭터를 제거
// 화이트 캐릭터 : 1~32번, 127번 아스키 코드값을 가지는것
System.out.println(" abdieksdf d dd ".trim());
}
}
댓글 없음:
댓글 쓰기