Vote ��ǥ 1 1
How To trim() in Javascript Ʈ���ϴ� ����� ()���� �ڹ� ��ũ��Ʈ
Angsuman Chakraborty angsuman Chakraborty��
March 17th, 2006 2006�� 3�� 17�� Javascript doesn't natively support trim on strings. �ڹ� ��ũ��Ʈ�� �⺻������ ������� �ʽ��ϴ� ���ڿ��� �����մϴ�. It is however very easy to implement with regular expressions. ���� ���� ǥ������ ���� ���� ������ ���ֽ��ϴ�.
Filed under �ؿ� Headline News ��� ���� ���� , How To �ϴ� ����� , Tech Note ��� ��� ���� , Web �� | |
| |
RSS 2.0 rss 2.0 | |
Email this Article ���� ������ ����
You may also like to read ������ ���� ���ֽ��ϴ� |





































January 20th, 2007 at 12:35 am 2007�� 1�� 20�Ͽ��� ���� 12�� 35��
Hi.. �ȳ��ϼ��� .. im new to javascript�� first of all i want to know whether javascript and jscript is same.. ���� ���� ù ��°�� ��� �ڹ� ��ũ��Ʈ�� �ڹ� ��ũ��Ʈ�� JScript�� ���θ� �˰� �;��� ���� .. or any other difference�� and plz guide me what is the use of trim function�� �Ǵ� �ٸ� �������� �����Դϱ ���� plz �ȳ� �� Ʈ���� ����� ����ϴ¡�
January 20th, 2007 at 12:36 am 2007�� 1�� 20�Ͽ��� ���� 12�� 36��
How to validate the forms in javascript�� �ڹ� ��ũ��Ʈ�� ��ȿ���� Ȯ���ϴ� ����� �������
February 9th, 2007 at 2:46 am 2007�� 2�� 9�Ͽ��� ���� 2�� 46��
uday plese try to understand yarr, why ur try to javascruipt go to your bad and just sleeping yarr, edighot ��� plese yarr �����Ϸ��� ����ϴ� ��, �� ��Ű javascruipt�Ϸ��� �ڰ� �̵��Ͽ� �ҷ� �� ���� yarr, edighot
July 18th, 2007 at 1:19 pm 2007�� 7�� 18�Ͽ��� ���� 1�� 19��
// This function is for stripping leading and trailing spacesfunction trim(str) { if (str != null) { var i; for (i=0; i=0; i–) { if (str.charAt(i)!=�� ��) { str=str.substring(0,i+1); break; } } if (str.charAt(0)==�� ��) { return ����; } else { return str; } }} / /�� �Լ��� ��Ʈ���� �����ϰ� ���� spacesfunction Ʈ�� (str) (��� (str! = ��) (���� ����;�� (���� = 0; �� = 0; ���� -) (��� (str.charat (1)! = "") (str = str.substring (0, ���� +1); �� �ð�;))�� (str.charat (0) == "") (��ȯ "";) �ٸ� ��� (��ȯ str;)))
August 1st, 2007 at 11:45 am 2007�� 8�� 1�Ͽ��� ���� 11�� 45��
this is my comment ok sorry �̰��� ���� �ڸ�Ʈ�� Ȯ�� �˼��մϴ�
November 15th, 2007 at 5:57 am 2007�� 11�� 15�Ͽ��� ���� 5�� 57��
This should actually be as follows: �̰��� ����� ������ �����ϴ� :
surname = surname.replace(/^\s+/, ����).replace(/\s+$/, ����); �� = surname.replace (/ ^ \�� + /, ""). �ٲٱ� (/ \�� + $ /, "");
December 5th, 2007 at 12:42 am 2007�� 12�� 5�Ͽ��� ���� 12�� 42��
function trim(str, chars) { ����� Ʈ�� (str, ����) (
return ltrim(rtrim(str, chars), chars); ��ȯ ltrim (rtrim (str, ����), ����);
} )
function ltrim(str, chars) { ����� ltrim (str, ����) (
chars = chars || ��\\s��; ���� = ���� | | "\ \��";
return str.replace(new RegExp(��^[" + chars + "]+��, ��g��), ����); ��ȯ str.replace (�� ������ ("^[" + ���� + "]+", "g"), "");
} )
function rtrim(str, chars) { ����� rtrim (str, ����) (
chars = chars || ��\\s��; ���� = ���� | | "\ \��";
return str.replace(new RegExp(��[" + chars + "]+$��, ��g��), ����); ��ȯ str.replace (�� ������ ( "["+ ���� + "]+$", "g"), "");
} )
March 31st, 2008 at 4:40 am 2008�� 3�� 31�Ͽ��� ���� 4�� 40��
To answer this.. �� �亯�� .. Javascript and Jscript are the same meaning with the different versioning. �ڹ� ��ũ��Ʈ�� JScript�� �ٸ� ����� ������ �ǹ̰��ֽ��ϴ�. Jscript is the version of Microsoft javascript. JScript�� ������ microsoft�� �ڹ� ��ũ��Ʈ�մϴ�. Some time the Document Object Model might differ from the Javascript. �ణ�� �ð� �ڹ� ��ũ��Ʈ�� ���� ��ü �� �ٸ� ���ֽ��ϴ�. And Jscript works only on IE browser. ��, JScript�� �������� �۵��մϴ�.
This might answer your question. �̰��� ������ �� ����մϴ�.
http://javascript.about.com/library/bljscript.htm
Thanks for the trim code. Ʈ�� �ڵ带 �ּż� �����մϴ�.
Thanks. thanks.
April 5th, 2008 at 8:18 am 2008�� 4�� 5�Ͽ��� ���� 8�� 18��
i want to search the javascript questions �ڹ� ��ũ��Ʈ �� ���� �˻� ����� �;��
April 5th, 2008 at 8:22 am 2008�� 4�� 5�Ͽ��� ���� 8�� 22��
to know the java script books �ڹ� ��ũ��Ʈ�� å�� �˰�
April 25th, 2008 at 2:16 am 2008�� 4�� 25�� 2:16 �ֿ�
Can also implement a trim function by extending the string type using a prototype. ���� Ʈ�� ����� �����ϴ� ������ Ÿ���� ����Ͽ� Ȯ���ϴ� ���ڿ��� �Է��մϴ�. Have a look at ������ http://whadiz.com/c/whatis.aspx/programming/javascript/javascript_trim