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(0, 2); //์์์์น, ์ด ์์น ์ ๊น์ง // ์๋
์ถ๋ ฅ
System.out.println("str9 = "+ subStr);
String subStr2 = str9.substring(3, 6); // ๋ฐ๊ฐ์
System.out.println("str9 = "+ subStr2);
|
cs |
๋ณ์.split( ํด๋น ๋ฌธ์์ด์์ ์๋ฅผ ๊ธฐ์ค char);
๋ณ์. substring( ์๋ฅด๊ธฐ์ํ ์์ ์์น, ์ด ์์น ์ ๊น์ง);
๋๊ธ