728x90
๋ฐ์ํ
1. ๋ฌธ์์ด ๋ฉ์๋ : ๋ณ๊ฒฝ : slice() : ๋ฌธ์์ด์์ ์ํ๋ ๊ฐ์ ์ถ์ถ
slice() : ๋ฌธ์์ด์์ ์ํ๋ ๊ฐ์ ์ถ์ถํฉ๋๋ค.
//slice(์์ ์์น)
//slice(์์ ์์น, ๋๋๋ ์์น)//๋๋๋ ์์น ๊ฐ์ด ์์ ์์น ๊ฐ๋ณด๋ค ์ปค์ผํจ
//substr(์์์์น)
//substr(์์์์น, ๊ธธ์ด)
const str1 = "javascript reference";
const currentStr1 = str1.slice(0); //javascript reference
const currentStr2 = str1.slice(1); //avascript reference
const currentStr3 = str1.slice(2); //vascript reference
const currentStr4 = str1.slice(0, 1); //j
const currentStr5 = str1.slice(0, 2); //ja
const currentStr6 = str1.slice(0, 3); //jav
const currentStr7 = str1.slice(1, 2); //av
const currentStr8 = str1.slice(1, 3); //av
const currentStr9 = str1.slice(1, 4); //avs
const currentStr10 = str1.slice(-1); //e
const currentStr11 = str1.slice(-2); //ce
const currentStr12 = str1.slice(-3); //nce
const currentStr13 = str1.slice(-3, -1); //nc
const currentStr14 = str1.slice(-3, -2); //n
const currentStr15 = str1.slice(-3, -3); //n
const currentStr16 = str1.slice(1, 4); //ava
const currentStr17 = str1.slice(4, 1); //''
const currentStr18 = str1.substring(4, 1); //ava
const currentStr19 = str1.substring(1, 4); //ava
//substring()์ ์์ ์์น์ ๋๋๋ ์์น๊ฐ์ ํฌ๊ธฐ์ ์ํฅ์ด ์๋ค. ์๋์ผ๋ก ๋ฐ๊ฟ์ค
const currentStr20 = str1.substr(0); //javascript reference
const currentStr21 = str1.substr(1); //avascript reference
const currentStr22 = str1.substr(2); //vascript reference
const currentStr23 = str1.substr(0, 1); //j
const currentStr24 = str1.substr(0, 2); //ja
const currentStr25 = str1.substr(0, 3); //jav
const currentStr26 = str1.substr(1, 2); //av
const currentStr27 = str1.substr(1, 3); //ava
const currentStr28 = str1.substr(1, 4); //avas
const currentStr29 = str1.substr(-1); //e
const currentStr30 = str1.substr(-2); //ce
const currentStr31 = str1.substr(-3); //nce
const currentStr32 = str1.substr(-1, 1); //e
const currentStr33 = str1.substr(-2, 2); //ce
const currentStr34 = str1.substr(-3, 3); //nce
02. ๋ฌธ์์ด ๋ฉ์๋ : slice() substring() substr()
๋ฌธ์์ด์์ ์ํ๋ ๊ฐ์ ์ถ์ถํ์ฌ ๋ฌธ์์ด์ ๋ฐํํ๋ ๋ฉ์๋์ ๋๋ค.
"๋ฌธ์ง์ด".slice(์์ ์์น)
"๋ฌธ์ง์ด".slice(์์ ์์น, ๋๋๋ ์์น)
//๋๋๋ ์์น ๊ฐ์ด ์์ ์์น ๊ฐ๋ณด๋ค ์ปค์ผํจ
//substring()์ ์์๊ฐ์ด ๋๋๋ ๊ฐ๋ณด๋ค ํด ๊ฒฝ์ฐ ๋ ๊ฐ์ ๋ฐ๊ฟ์ ์ฒ๋ฆฌ(์๋ฌ๋ฐฉ์ง) "๋ฌธ์ง์ด".substr(์์์์น)
"๋ฌธ์ง์ด".substr(์์์์น, ๊ธธ์ด)
"๋ฌธ์ง์ด".slice(์์ ์์น, ๋๋๋ ์์น)
//๋๋๋ ์์น ๊ฐ์ด ์์ ์์น ๊ฐ๋ณด๋ค ์ปค์ผํจ
//substring()์ ์์๊ฐ์ด ๋๋๋ ๊ฐ๋ณด๋ค ํด ๊ฒฝ์ฐ ๋ ๊ฐ์ ๋ฐ๊ฟ์ ์ฒ๋ฆฌ(์๋ฌ๋ฐฉ์ง) "๋ฌธ์ง์ด".substr(์์์์น)
"๋ฌธ์ง์ด".substr(์์์์น, ๊ธธ์ด)
//slice(์์ ์์น)
//slice(์์ ์์น, ๋๋๋ ์์น)//๋๋๋ ์์น ๊ฐ์ด ์์ ์์น ๊ฐ๋ณด๋ค ์ปค์ผํจ
//substr(์์์์น)
//substr(์์์์น, ๊ธธ์ด)
const str1 = "javascript reference";
const currentStr1 = str1.slice(0); //javascript reference
const currentStr2 = str1.slice(1); //avascript reference
const currentStr3 = str1.slice(2); //vascript reference
const currentStr4 = str1.slice(0, 1); //j
const currentStr5 = str1.slice(0, 2); //ja
const currentStr6 = str1.slice(0, 3); //jav
const currentStr7 = str1.slice(1, 2); //av
const currentStr8 = str1.slice(1, 3); //av
const currentStr9 = str1.slice(1, 4); //avs
const currentStr10 = str1.slice(-1); //e
const currentStr11 = str1.slice(-2); //ce
const currentStr12 = str1.slice(-3); //nce
const currentStr13 = str1.slice(-3, -1); //nc
const currentStr14 = str1.slice(-3, -2); //n
const currentStr15 = str1.slice(-3, -3); //n
const currentStr16 = str1.slice(1, 4); //ava
const currentStr17 = str1.slice(4, 1); //''
const currentStr18 = str1.substring(4, 1); //ava
const currentStr19 = str1.substring(1, 4); //ava
//substring()์ ์์ ์์น์ ๋๋๋ ์์น๊ฐ์ ํฌ๊ธฐ์ ์ํฅ์ด ์๋ค. ์๋์ผ๋ก ๋ฐ๊ฟ์ค
const currentStr20 = str1.substr(0); //javascript reference
const currentStr21 = str1.substr(1); //avascript reference
const currentStr22 = str1.substr(2); //vascript reference
const currentStr23 = str1.substr(0, 1); //j
const currentStr24 = str1.substr(0, 2); //ja
const currentStr25 = str1.substr(0, 3); //jav
const currentStr26 = str1.substr(1, 2); //av
const currentStr27 = str1.substr(1, 3); //ava
const currentStr28 = str1.substr(1, 4); //avas
const currentStr29 = str1.substr(-1); //e
const currentStr30 = str1.substr(-2); //ce
const currentStr31 = str1.substr(-3); //nce
const currentStr32 = str1.substr(-1, 1); //e
const currentStr33 = str1.substr(-2, 2); //ce
const currentStr34 = str1.substr(-3, 3); //nce
728x90
๋ฐ์ํ
'์๋ฐ์คํฌ๋ฆฝํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
toUpperCase() / toLowerCase() (4) | 2022.08.17 |
---|---|
์ ๊ทํํ์ (4) | 2022.08.17 |
indexOf()/lastIndexOf() (6) | 2022.08.17 |
๋ด์ฅํจ์ (3) | 2022.08.15 |
๋ฐฐ์ด ๊ด๋ จ ๋ฉ์๋ (10) | 2022.08.11 |
๋๊ธ