Java/String
Java String 예시 4(subString, trim, toLowerCase, toUpperCase)
S.T.Lee
2022. 11. 14. 21:18
package lec13.StringLec.lec01;
public class StringLec04 {
public static void main(String[] args) {
//subString
//뱐수가 하나일때는 해당 인덱스 이후의 모든것
//변수가 두개일때는 해당 범위 안의 것
String strSubstring01 = "Hello, World";
String returnSubs01 = strSubstring01.substring(7);
String returnSubs02 = strSubstring01.substring(0, 5);
System.out.println(returnSubs01 + "......" + returnSubs02);
System.out.println("=======================");
//trim
String strTrim01 = " Hello, world! ";
String trimResult01 = strTrim01.trim();
System.out.println(trimResult01);
strTrim01 = " Hello, world! ";
System.out.println(strTrim01.length());
String trimResult02 = strTrim01.trim();
System.out.println(trimResult02.length());
System.out.println("=======================");
//toLowerCase - 소문자로 낮추기
String lowerCase = "Hello, world!";
System.out.println("lower 전 : " + lowerCase);
System.out.println("lower 후 : " + lowerCase.toLowerCase() );
//toUpperCase
String strUpperCase = "hello, world";
String resultUpper = strUpperCase.toUpperCase();
System.out.println(resultUpper);
}
}