 |
|
|  |
[JavaScript] ÀÚ¹Ù½ºÅ©¸³Æ® :: ¹®ÀÚ¿ ÀÚ¸£±â |
|
|
 |
12³â Àü |
ÀÚ¹Ù½ºÅ©¸³Æ®¿¡¼.. split À» ¾µ°æ¿ì..
var s_data = "2005-03-25"; // À߶ó¾ß µÇ´Â °ª..
var array_data = s_data.split("-"); // split ÇÔ¼ö»ç¿ë..
var s_year = array_data[0]; // À߶óÁø °ª ¹è¿..
var s_month = array_data[1];
var s_day = array_data[2];
[ÀÚ¹Ù½ºÅ©¸³Æ® ¹®ÀÚ¿ ±æÀÌ´ë·Î ÀÚ¸£±â]
function cutStr(str,limit){
var tmpStr = str;
var byte_count = 0;
var len = str.length;
var dot = "";
for(i=0; i<len; i++){
byte_count += chr_byte(str.charAt(i));
if(byte_count == limit-1){
if(chr_byte(str.charAt(i+1)) == 2){
tmpStr = str.substring(0,i+1);
dot = "...";
}else {
if(i+2 != len) dot = "...";
tmpStr = str.substring(0,i+2);
}
break;
}else if(byte_count == limit){
if(i+1 != len) dot = "...";
tmpStr = str.substring(0,i+1);
break;
}
}
document.writeln(tmpStr+dot);
return true;
}
function chr_byte(chr){
if(escape(chr).length > 4)
return 2;
else
return 1;
}
»ç¿ëÀº ¹®ÀÚ¿À» Ãâ·ÂÇÒ °÷¿¡ <script>cutStr("±æÀÌ°¡ ±ä ¿ø·¡ÀÇ ¹®ÀÚ¿",5)</script>¿Í °°ÀÌ ½áÁÖ½Ã¸é ¹ÙÀÌÆ® ´ÜÀ§·Î ÀÚ¸£°í Çѱ۰ú °°ÀÌ 2byte°¡ µÇ´Â ±ÛÀÚ´Â 1byteÁÙ¿©¼ Ãâ·ÂÇÕ´Ï´Ù.
* Ãâó : http://www.zeroboard.com/?mid=study_javascript&page=7&sort_index=voted_count&order_type=desc&document_srl=1505452
[½ÃÀÛÀ妽º+³¡À妽º·Î ÀÚ¸£±â]
½ÇÇà½ÃÄÑ º¸½Ã¸é...ÀÌÇØ°¡ µÉ °Ì´Ï´Ù.. µµ¿òÀÌ µÇ½Ã±æ ^^*
======================================================
<SCRIPT LANGUAGE="JavaScript">
str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
document.write("str returns: " + str + "<BR>");
document.write("str.substring(0, str.length) returns: ");
document.write(str.substring(0, str.length) + "<BR>");
document.write("str.substring(0, 1) returns: ");
document.write(str.substring(0, 1) + "<BR>");
document.write("str.substring(0, 5) returns: ");
document.write(str.substring(0, 5) + "<BR>");
document.write("str.substring(-5, 5) returns: ");
document.write(str.substring(-5, 5) + "<BR>");
document.write("str.substring(8, 13) returns: ");
document.write(str.substring(8, 13) + "<BR>");
document.write("str.substring(8, 99) returns: ");
document.write(str.substring(8, 99) + "<BR>");
document.write("str.substring(9, 9) returns: ");
document.write(str.substring(9, 9) + "<BR>");
document.write("str.substring(9, 8) returns: ");
document.write(str.substring(9, 8) + "<BR>");
document.write("str.substring(9, 0) returns: ");
document.write(str.substring(9, 0) + "<BR>");
document.write("str.length returns: ");
document.write(str.length + "<BR>");
document.write("str.substring( str.length-3, str.length) returns: ");
document.write(str.substring( str.length-3, str.length) + "<BR>");
</SCRIPT>
================================================
str.substring(½ÃÀÛÀ妽º, ³¡À妽º)
================================================
Ãâó : PHP½ºÄð
[ÀÚ¹Ù½ºÅ©¸³Æ® :: ¹®ÀÚ¿ ¿ìÃø¿¡¼ Àß¶ó¼ °¡Á®¿À±â]
¿¹·Î½á ÁÖ¹®½Ã Àû¸³±ÝÀ» ÀÔ·ÂÇÑ ±Ý¾×ÀÌ 1000¿ø ´ÜÀ§·Î¸¸ ÀÔ·ÂÇß´ÂÁö È®ÀÎÇÏ°íÀÚ ÇÑ´Ù¸é ¿ìÃø 3ÀÚ¸®¿Í ºñ±³ÇؾßÇϹǷΠÀ̶§ substrÀ» ÀÌ¿ëÇϸéµÊ
"5700".length 4À̹ǷΠ¿©±â¿¡ 4 - 3 = 1 À§Ä¡ ºÎÅÍ ¹®ÀÚ¸¦ ¹Þ¾Æ¿È
Áï °á°ú´Â "700"À» ¹Þ¾Æ ¿À°ÔµÊ
<form name="form" method="post">
<input type="text" name="reservein" value="5700">
</form>
<script>
var ff = document.form.reservein.value;
// ºñ±³±¸¹®Àº 1000º¸´Ù ÀÛÀºÁö ¶Ç´Â ¾Æ·¡Ã³·³ 000 ÀÏÄ¡ÇÑÁö ó·³ ÀÚ½ÅÀÇ ÄÚµù ½ºÅ¸ÀÏ·Î ±¸ÇöÇϸéµÊ. ^^
if(ff.substr((ff.length-3) != "000") {
alert("1,000¿ø ´ÜÀ§·Î ÀÔ·ÂÇϼ¼¿ä!");
}
</script> |
|
̵̧ : 523 |
̵̧
¸ñ·Ï
|
|
|  |
|