JAVA :: substring ํ•จ์ˆ˜

s_omiยท2021๋…„ 8์›” 3์ผ
0

JAVA (์ž๋ฐ”)

๋ชฉ๋ก ๋ณด๊ธฐ
36/62
post-thumbnail
post-custom-banner

๐Ÿ“ substring ํ•จ์ˆ˜

๐Ÿ’ก String substring(int index)

index ์ดํ›„์˜ ๋ชจ๋“  ๋ฌธ์ž์—ด์„ ๋ฆฌํ„ด์‹œํ‚ค๋Š” ํ•จ์ˆ˜
โš  ๊ณต๋ฐฑ(๋„์–ด์“ฐ๊ธฐ)๋„ ํ•˜๋‚˜์˜ ์ธ๋ฑ์Šค๋กœ ํฌํ•จ๋จ.

  • ์˜ˆ์‹œ
String s = "I can do";
System.out.print(s.substring(4));

=> ๊ฒฐ๊ณผ : n do  // ๊ณต๋ฐฑ๋„ ์ธ๋ฑ์Šค๋กœ ํฌํ•จ

๐Ÿ’ก String substring(int beginIndex, int endIndex)

beingIndex ๋ถ€ํ„ฐ endIndex ์ „๊นŒ์ง€ ํฌํ•จ๋˜๋Š” ์ธ๋ฑ์Šค์˜ ๋ฌธ์ž์—ด์„ ๋ฆฌํ„ด์‹œํ‚ค๋Š” ํ•จ์ˆ˜

  • ์˜ˆ์‹œ
String s = "I can do whatever I want"; 
System.out.print(s.substring(9, 17));   // r์˜ ์ธ๋ฑ์Šค : 16

=> ๊ฒฐ๊ณผ : whatever
profile
๊ณต๋ถ€ํ•œ ๊ฑฐ ์˜ฌ๋ ค์š” :)

0๊ฐœ์˜ ๋Œ“๊ธ€