๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“œ ์ž๋ฐ” Java

์ž๋ฐ”(JAVA) - ๋Œ€ํ‘œ์ ์ธ String ๋ฉ”์†Œ๋“œ, / ๋ฌธ์ž์—ด์„ ์ž๋ฅธ๋‹ค .split/ ๋ฌธ์ž์—ด์˜ ๋ฒ”์œ„๋กœ ์ž๋ฅด๋Š” ํ•จ์ˆ˜ substring

by Meteora_ 2021. 1. 25.
728x90
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
35
36
37
 // ๋ฌธ์ž์—ด์„ ์ž๋ฅธ๋‹ค.
    // split
    
    /*
     
     aaaa-bbbb-ccccc
     aaaa
     bbb
     ccccc// ์ด๊ฒƒ๋งŒ ๋•Œ์„œ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์„๋•Œ!
     
     ํ™๊ธธ๋™-24-2001/12/23-์„œ์šธ์‹œ
     ์•ˆ์‹  - 21-2001/10/11
     
     */
    String str8 = "ํ™๊ธธ๋™-24-2001/12/23-์„œ์šธ์‹œ-181.1";
    String split[] =str8.split("-");
    
    System.out.println(split.length);   // 5             ์ถœ๋ ฅ
    System.out.println(split[0]);        // ํ™๊ธธ๋™
    System.out.println(split[1]);        // 24
    System.out.println(split[2]);        // 2001/12/23
    System.out.println(split[3]);        // ์„œ์šธ์‹œ
    System.out.println(split[4]);        // 181.1
    
    
 
    // ๋ฌธ์ž์—ด์˜ ๋ฒ”์œ„๋กœ ์ž๋ฅด๋Š” ํ•จ์ˆ˜
    // substring
    
    String str9 = "์•ˆ๋…• ๋ฐ˜๊ฐ€์›Œ์š” ๊ฑด๊ฐ•ํ•ด์š”";
    String subStr = str9.substring(02); //์‹œ์ž‘์œ„์น˜, ์ด ์œ„์น˜ ์ „๊นŒ์ง€  // ์•ˆ๋…• ์ถœ๋ ฅ
    
    System.out.println("str9 = "+ subStr);
    
    String subStr2 = str9.substring(36); // ๋ฐ˜๊ฐ€์›Œ 
    System.out.println("str9 = "+ subStr2);
    
cs

๋ณ€์ˆ˜.split( ํ•ด๋‹น ๋ฌธ์ž์—ด์—์„œ ์ž๋ฅผ ๊ธฐ์ค€ char);

 

๋ณ€์ˆ˜. substring( ์ž๋ฅด๊ธฐ์œ„ํ•œ ์‹œ์ž‘ ์œ„์น˜, ์ด ์œ„์น˜ ์ „๊นŒ์ง€);

 

๋Œ“๊ธ€