- String.prototype.trim = function()
- {
- var start, end;
- start = 0;
- end = this.length - 1;
- while(start <= end && this.charAt(start)==' ')
- {
- start++;
- }
- while(start <= end && this.charAt(end) == ' ')
- {
- end--;
- }
- return this.substing(start,end+1);
- }
-
- String.prototype.toCharArray = function()
- {
- var chs = [];
- for(var x = 0; x < this.length; x++)
- {
- chs[x] = this.charAt(x);
- }
- return chs;
- }
-
- String.prototype.reverse = function()
- {
- var arr = this.toCharArray();
- function swap(arr,a,b)
- {
- var temp = arr[a];
- arr[a] = arr[b];
- arr[b] = temp;
- }
-
- for(var x = 0, y = arr.length - 1; x < y; x++, y--)
- {
- swap(arr,x,y);
- }
- return arr.join("");
- }
![](//img-blog.csdn.net/20161010092628182?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
posted @
2016-11-11 15:39
光何
阅读(
160)
评论()
编辑
收藏
举报