split() 함수를 사용하여 .(마침표) /(슬래시) \\(역슬래시) 로 구분하기

\\(역슬래시 2개)를 붙여서 구분한다



java)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.blog;
 
public class BlogEx001 {
 
    public static void main(String[] args) {
        String strTest1 = "ABCD.가나다라.1234";        //.(마침표)로 구분
        String strTest2 = "사과/바나나/딸기";    // /(슬래시)로 구분
        String strTest3 = "노트북\\휴대폰\\티비";    //\(역슬래시)로 구분
        
        /** \\ (역슬래시2개) 로 구분 */
        String[] arrTest1 = strTest1.split("\\.");
        String[] arrTest2 = strTest2.split("\\/");
        String[] arrTest3 = strTest3.split("\\\\");
        
        
        /** 출력 */
        for(int i=0; i<arrTest1.length; i++){
            System.out.println(arrTest1[i]);
        }
        System.out.println();
        
        for(int i=0; i<arrTest2.length; i++){
            System.out.println(arrTest2[i]);
        }
        System.out.println();
        
        for(int i=0; i<arrTest3.length; i++){
            System.out.println(arrTest3[i]);
        }
        System.out.println();
        
    }
}
 
cs



결과





'IT > - 프로그래밍' 카테고리의 다른 글

코코스 Cocos 설치하기  (0) 2017.01.04
자바 두 날짜사이의 차이 계산  (0) 2017.01.03
MAC 잠자기 기능  (0) 2016.12.03
안드로이드 PCI값 가져오기  (0) 2016.12.03
안드로이드 eNB값 가져오기  (0) 2016.12.03

+ Recent posts