Help!!!!!! Eliminate spaces

Results 1 to 3 of 3

Thread: Help!!!!!! Eliminate spaces

  1. #1
    Join Date
    Dec 1969

    Default Help!!!!!! Eliminate spaces

    When a user enters a form, how can i track and eliminate<BR>spaces.<BR>Single space is ok, but if he inserts double,tripple,...<BR>i dont want to insert it in the database, double space or more.<BR>Single space is ok,<BR>What code should I write in asp to track this and insert in database a proper format, single space is allowed.<BR>But if double or tripple ... etc i want to eliminate it

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default RE: Help!!!!!! Eliminate spaces

    You have to parse throuogh the string and look for more than on space together...<BR><BR>write a function to replace more than one space with one space...<BR><BR>WAIT<BR><BR>how about you split on a space then check for a value in the elements of the array as you loop through it and then concatinate it to a string where you insert into the Db<BR><BR>while you loop though the array trim the data and concatinate with a space...if there is no "real" data in the array element you ignore it....very ugly i know but i cannot think of anything at the top of my hat.<BR><BR>

  3. #3
    Tripp Guest

    Default RE: Help!!!!!! Eliminate spaces

    Sounds like what you need is the regualar expression object.<BR><BR>Try this block of code:<BR><BR> Dim strRegExp: strRegExp = " test string "<BR> <BR> Dim patrn: patrn = "ss+"<BR>&#039;the pattern above will match on 2 spaces followed by any<BR>&#039;amount of white space<BR> Dim strFoo<BR> Dim RetStr<BR> <BR>&#039;set up the regular expression object <BR> Dim objregExp: Set objregExp = New RegExp<BR>&#039;carry out the replacement everytime we find a match <BR> objregExp.Global = True<BR> objregExp.Pattern = patrn<BR> objregExp.IgnoreCase = True<BR><BR>&#039;replace the offending pattern and replace it with a single space<BR> strRegExp = Trim(objregExp.Replace(strRegExp, " "))<BR><BR>&#039;we called trim so to get rid of any leading and trailing spaces<BR><BR>That&#039;s it. This should solve your problem.<BR><BR>Good luck,<BR><BR>Tripp

Posting Permissions

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