String 클래스 정리


1) toLowerCase
->문자열에서 대문자를 소문자로 바꾼다.
예)String str="ABC"
    String toLower=str.toLowerCase();
    결과: abc

2)toUpperCase
->문자열에서 소문자를 대문자로 바꾼다.
    String str="abc"
    String toLower=str.toUpperCase();
    결과: ABC

3)concat
->문자와 문자를 결합해준다.
  String str="Korea"
  Sting str2="is fighting"
  String concat=str.concat(str2);
 결과:Korea is fighting

4)replace
->문자열에 지정한 문자" "가 있으면 새로 지정한 문자" "로 바꾸어 출력한다
   String str="A*B*C*D"
   String replace=str.replace("*","-");
  결과: A-B-C-D

-->>만약 여러개를 한번에 바꾸고 싶으면 연결 해 붙인다.
.예)input.replace(".","").replace("!", "").replace(",", "");


5)replaceall(정규표현식이 무엇인지는 정규표현식 글 참고)
->정규 표현식을 지정한 문자로 바꾸어 출력한다
String str = "AB CD";
String replaceAll = str.replaceAll("\\p{Space}", "*");
System.out.println("replaceAll: " + replaceAll);

댓글

이 블로그의 인기 게시물

(네트워크)폴링방식 vs 롱 폴링방식

(ElasticSearch) 결과에서 순서 정렬

(18장) WebSocekt과 STOMP를 사용하여 메시징하기