예전에 한참 스크립트와 생활을 할 때 봤던 내용인데 까먹을까봐 정리해야 겠습니다 ㅋㅋㅋ
String의 prototype에 replaceAll함수를 추가하는 방식입니다.
split함수를 이용하여 바꿀 부분으로 자르고 join으로 합치는 방식은 어떤 분이 생각했는지 몰라도 참 대단한 발상인 것 같았습니다.
Split, Join 함수의 정의를 보면 다음과 같습니다.
split Method (Windows Scripting - JScript)
Returns the array of strings that results when a string is separated into substrings.
stringObj.split([separator[, limit]])

Arguments
stringObj
Required. The
String
object or literal to be split. This object is not modified by the
split
method.
separator
Optional. A string or an instance of a
Regular Expression
object identifying one or more characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
limit
Optional. A value used to limit the number of elements returned in the array.
댓글
댓글 쓰기