- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <!-- 현재 작성하고 있는 파일은 UTF-8 DOS파일입니다.-->
- <html xmlns="http://www.w3.org/1999/xhtml" lang="ko">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- </head>
- <body>
- <div id="ex_js_syntax">
- <script type="text/javascript" language="javascript">
- <!--
- function str_localecompare(){
- /* 문자열 비교 => 문자열변수.localeCompare("비교문자열")
- 반환값 0은 같고 1이나 -1은 문자열 서로 틀림 */
- var str_val = "hi nice to meet you";
- var str_val2 = "hi nice to meet you too";
- document.getElementById("string_localecompare").innerHTML = str_val.localeCompare(str_val2);
- }
- //-->
- </script>
- <form name="input_type" id="input_type" method="post" >
- <!-- 예제 박스에선 안됨 => form태그안에 form태그있으면 지워짐~ㅠ.ㅠ -->
- 문자열 => hi nice to meet you <br />
- <p id="string_localecompare" onclick="str_localecompare();">문자열 비교[클릭]</p>
- </form>
- </div>
- </body>
- </html>
--------------------------------------------------------------------------------------------
위 소스 예제 보기
문자열 비교 => 문자열변수.localeCompare("비교문자열")
반환값 0은 같고 1이나 -1은 문자열 서로 틀림
출처 & 인용 - http://www.w3schools.com/
'javascript > String()객체' 카테고리의 다른 글
String객체 replace() 문자열에서 찾는 문자열 문자 교체 (0) | 2014.02.01 |
---|---|
String객체 match() 문자열검사 및 정규표현식 검사 (0) | 2014.02.01 |
String객체 lastIndexOf() 문자열 찾는 문자 끝위치 반환 (0) | 2014.02.01 |
String객체 indexOf() 문자열 찾는 문자 첫위치 반환 (0) | 2014.02.01 |
String객체 fromCharCode() 문자열 아스키코드 문자 반환 (0) | 2014.02.01 |