---
title: "js去两端空格"
author: "shaq34"
date: "2009-06-30T15:27:46Z"
tags: []
slug: "js"
draft: false
lastmod: "2009-08-21T10:20:44Z"
id: 417667
url: "https://shaq34.iteye.com/blog/417667"
---

```java
function trim(s)   
{   
    try  
    {   
        return s.replace(/^\s+|\s+$/g,"");   
    }   
    catch(e)   
    {   
        return s;   
    }   
}
```