Vote �벼 1 1
How To trim() in Javascript �p��װš] �^�bJavaScript
Angsuman Chakraborty���Angsuman Chakraborty
March 17th, 2006 2006�~3��17�� Javascript doesn't natively support trim on strings. javascript��natively���d��勇�ֹΡC It is however very easy to implement with regular expressions.���L�A�o�O�D�`�e������A�P���h��F���C
Filed under���_�U Headline News�Y��s�D , �A How To�p�� , �A Tech Note�N���� , �A Web���� | |
| |
RSS 2.0 2.0 | |
Email this Article�q�l�l�峹
You may also like to read�z�]�i�H�QŪ |




































January 20th, 2007 at 12:35 am 2007�~1��20��b�W��12��35��
Hi..��.. im new to javascript�K first of all i want to know whether javascript and jscript is same..�Y�ɳq�T�s��JavaScript �K����A�ڷQ���D�O�_JavaScript�MJScript���O�ۦP��.. or any other difference�K and plz guide me what is the use of trim function�K�Υ����L���t���K �K�Mplz��n�ڦ�����ΰſ�\��K
January 20th, 2007 at 12:36 am 2007�~1��20��b�W��12��36��
How to validate the forms in javascript�K�p�����Ҫ��Φ��bJavaScript �K
February 9th, 2007 at 2:46 am 2007�~2��9��b�W��02��46��
uday plese try to understand yarr, why ur try to javascruipt go to your bad and just sleeping yarr, edighot�Q�N���I���U�����ϼй��դF��yarr �A������Q�Ԧc�^�X����javascruipt���z�����n�A�u�O��ı�A yarr �A edighot
July 18th, 2007 at 1:19 pm 2007�~7��18��b�U��1��19��
// This function is for stripping leading and trailing spacesfunction trim(str) { if (str != null) { var i; for (i=0; i=0; i�V) { if (str.charAt(i)!=�� ��) { str=str.substring(0,i+1); break; } } if (str.charAt(0)==�� ��) { return ����; } else { return str; } }} / /�o�ӥ\��O��������ɩM���Hspacesfunction�װš]��STR �^ �]�p�G�]��STR �I =�š^ �]�L�\; �G �]�@= 0 ;��= 0 ;�@�^ �]�p�G�] str.charat �]�@�^ �I = �� �� �^ �]��STR = str.substring �] 0 �A��1 �^ ;��}; �^ �^�p�G�] str.charat �] 0 �^ == �� �� �^ �]��^�� �� ; �^ �]�_�h��^�i�å����i; �^ �^ �^
August 1st, 2007 at 11:45 am 2007�~8��1��W��11��45��
this is my comment ok sorry�o�O�ڪ���T�w��p
November 15th, 2007 at 5:57 am 2007�~11��15��b�W��05��57��
This should actually be as follows:�o��ڤW���p�U�G
surname = surname.replace(/^\s+/, ����).replace(/\s+$/, ����);�m= surname.replace �] / ^ \ s + / �� �A �� �^ �C��N�] / \ s +��/ �A �� �� �^ ;
December 5th, 2007 at 12:42 am 2007�~12��5��b�W��12��42��
function trim(str, chars) {�\��װš]��STR �A�r���^ �]
return ltrim(rtrim(str, chars), chars);��^ltrim �] rtrim �]��STR �A�r���^ �A�r�^ ;
} �^
function ltrim(str, chars) {�\��ltrim �]��STR �A�r���^ �]
chars = chars || ��\\s��;�r=�r| | �� \ \���� ;
return str.replace(new RegExp(��^[" + chars + "]+��, ��g��), ����);��^str.replace �]�sregexp��("^[" +�r+ "]+",���� G �� �^ �A �� �� �^ ;
} �^
function rtrim(str, chars) {�\��rtrim �]��STR �A�r���^ �]
chars = chars || ��\\s��;�r=�r| | �� \ \���� ;
return str.replace(new RegExp(��[" + chars + "]+$��, ��g��), ����);��^str.replace �]�sregexp���] �� [ �� +�r+ "]+$",���� G �� �^ �A �� �� �^ ;
} �^
March 31st, 2008 at 4:40 am 2008�~3��31��b�W��04��40��
To answer this..�n�^���o��.. Javascript and Jscript are the same meaning with the different versioning. JavaScript�MJScript���O�ۦP���N�q�P���P�������C Jscript is the version of Microsoft javascript. JScript���O������Microsoft��JavaScript �C Some time the Document Object Model might differ from the Javascript.�@�q�ɶ����ɹ�H�ҫ��i��|���Ҥ��P��JavaScript �C And Jscript works only on IE browser.�MJScript�u��IE�s��C
This might answer your question.�o�i��|�^���A�����D�C
http://javascript.about.com/library/bljscript.htm
Thanks for the trim code.�P�°ſ�N�X�C
Thanks.���¡C
April 5th, 2008 at 8:18 am 2008�~4��5��b�W��8��18��
i want to search the javascript questions�ڷQ�j����JavaScript���D
April 5th, 2008 at 8:22 am 2008�~4��5��b�W��8��22��
to know the java script books�n���D�A Java�}�������y
April 25th, 2008 at 2:16 am 2008�~4��25��b�W��02��16��
Can also implement a trim function by extending the string type using a prototype.�]�i�H��I�ſ�\��A����r�Ŧ������ϥΪ��쫬�C Have a look at���@�Ӭݬ� http://whadiz.com/c/whatis.aspx/programming/javascript/javascript_trim