JAVASCRIPT
JAVASCRIPT 문자열 자르기2
JDK's blog
2015. 11. 19. 00:04
안녕하세요
저번에 substirng함수를 알려드렸었죠..?
substr함수를 사용해서 문자열을 자르는 방법을 알려드릴께요
1
2
3
4
5
6
7
8
9
10 |
<script type="text/javascript">
function testAlert(){
var imsi = "2015-11-11";
console.log(imsi.substr(0,4)+"-"+imsi.substr(5,2)+"-"+imsi.substr(8,2));
}
</script>
<body onload = "testAlert()">
</body> |
cs |
문자열.substr(시작문자열,가져올문자열수)를 쓰면 필요한 문자열을 가져올 수 있습니다.
이렇게 결과가 나왔어요.. substring으로 해결이 안됬다면 이렇게 처리해서 해결해 보는 것도 좋은거 같아요.