블로그 이미지
올해목표 // 10월 어학연수 떠나자~ 자수씨

카테고리

전체글 (1457)
Brand New! (28)
주절주절 (213)
MOT (11)
해외쇼핑 (49)
쇼핑노트 (150)
취미생활 (94)
iPhone (4)
Eclipse (121)
Google (83)
Spring (31)
JAVA (176)
JavaScript (59)
WEB (49)
Database (20)
OS (26)
Tools (8)
Tips (26)
IT정보 (1)
Book (21)
Programming (37)
외부행사 (43)
주변인들 (17)
여행노트 (60)
학교생활 (30)
회사생활 (52)
사회생활 (5)
외국어공부 (12)
잡동사니 (30)
Total
Today
Yesterday
 
05-02 01:20
 

달력

« » 2024.5
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
 

최근에 올라온 글

최근에 달린 댓글

[JavaScript] replaceAll

JavaScript / 2009. 8. 12. 10:59

예전에 한참 스크립트와 생활을 할 때 봤던 내용인데 까먹을까봐 정리해야 겠습니다 ㅋㅋㅋ



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]])
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.

출처: MSDN (http://msdn.microsoft.com/en-us/library/t5az126b(VS.85).aspx)

join Method (Windows Scripting - JScript)

Updated: March 2009

Returns a string value consisting of all the elements of an array concatenated together and separated by the specified separator string.

arrayObj.join(separator) 
arrayObj

Required. An Array object.

separator

Required. A String object used to separate one element of an array from the next in the resulting String object. If omitted, the array elements are separated with a comma.

출처: MSDN (http://msdn.microsoft.com/en-us/library/59x7k999(VS.85).aspx)
split은 문자열 뿐만아니라 정규식으로도 잘라낼 수 있기 때문에 자바에서 쓰는 replaceAll과 거의 유사하게 결과를 볼 수 있을 것이라 생각됩니다. 하지만 수행속도는 당연히 떨어지겠죠...



요즘 회사일이 너무 자주 바껴서 정신이 읍네요 -_ㅜ...


Posted by 자수씨
, |

글 보관함

최근에 받은 트랙백