1 2 3
function getStringLength(str){ return(str.length+(escape(str)+"%u").match(/%u/g).length-1); }
function getStringLength(str){ return(str.length+(escape(str)).match(/%u/g).length); }
“%u”하고 -1을 하는 특별한 이유가 있나요?
match 함수의 특성 때문에 그렇습니다. match는 하나 이상의 일치하는 값이 있으면 그 값을 포함하는 배열을 리턴하지만, 일치하는 값이 없을 경우 null을 리턴합니다. 그러므로 반드시 하나 이상의 매치를 만들기 위해서 %u를 강제로 추가시킨 것이고, 결과값에서 1을 빼주는 것이죠.
이론상으로는 그렇고… 실제 질문하신 대로 사용해도 에러가 발생하지 안더군요.
참고 링크 http://livedocs.adobe.com/flash/9.0_kr/ActionScriptLangRefV3/String.html#match() http://www.devguru.com/Technologies/ecmascript/quickref/string_match.html
필요해서 검색했는데 딱 나오네요~ 동작도 잘하구~~ 잘쓰겠습니다. 감사해요
넹 ^^
Name (required)
E-mail (required)
URI
Your Comment
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">
function getStringLength(str){
return(str.length+(escape(str)).match(/%u/g).length);
}
“%u”하고 -1을 하는 특별한 이유가 있나요?
match 함수의 특성 때문에 그렇습니다.
match는 하나 이상의 일치하는 값이 있으면 그 값을 포함하는 배열을 리턴하지만, 일치하는 값이 없을 경우 null을 리턴합니다. 그러므로 반드시 하나 이상의 매치를 만들기 위해서 %u를 강제로 추가시킨 것이고, 결과값에서 1을 빼주는 것이죠.
이론상으로는 그렇고…
실제 질문하신 대로 사용해도 에러가 발생하지 안더군요.
참고 링크
http://livedocs.adobe.com/flash/9.0_kr/ActionScriptLangRefV3/String.html#match()
http://www.devguru.com/Technologies/ecmascript/quickref/string_match.html
필요해서 검색했는데 딱 나오네요~
동작도 잘하구~~
잘쓰겠습니다. 감사해요
넹 ^^