SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict svcghost's Avatar
    Join Date
    Oct 2010
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    trim() function in Chrome not working

    Hey guys,

    Am I missing something here? My trim() function seems to halt JavaScript execution in Chrome. Why is this?

    Code:
    function trim(s) {
    			s = s.replace(/(^\s*)|(\s*$)/gi,"");
    			s = s.replace(/[ ]{2,}/gi," ");
    			s = s.replace(/\n /,"\n");
    			return s;
    		}

    It works in IE and firefox.. wait no it doesn't. not anymore. wtf.

  2. #2
    SitePoint Addict svcghost's Avatar
    Join Date
    Oct 2010
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems to work for some things but not others. It will work for a flat out string, but not a variable.

  3. #3
    SitePoint Addict svcghost's Avatar
    Join Date
    Oct 2010
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it to work. I was passing the function an object instead of a string. Ooops!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •