SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2003
    Location
    Melbourne, Australia
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    trimming spaces ala asp

    hi all

    how can i trim spaces from a string
    sorry i'm in a rush so i can't search for the answer

    thanks

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <html>
      <head>
        <title>Trim function</title>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
        <script type="text/javascript">
          function trim(s)
          {
            return s.replace(/^\s*|\s*$/g, '');
          }
        </script>
      </head>
      <body>
        <form>
          <input type="text" id="txt1" name="txt1" value="   blah   blah   blah   "><br>
          <input type="button" value="Trim!" onclick="this.form.txt1.value = trim(this.form.txt1.value);">
        </form>
      </body>
    </html>


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
  •