Bytes Expert Newtork: Connect with experts in IT / Business | Expert Topics



Search


Go Back   Programmers Resource > Code Section > ASP Articles
User Name
Password


 
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old 06-12-2003, 11:53 AM
Angelika Angelika is offline
Moderator
 
Join Date: May 2003
Location: NJ
Posts: 125
Remove multiple spaces between words in a string.

Dim str
str = " Leading and trailing spaces... "
str = Trim(str)

'****At this point str = "Leading and trailing spaces..."

While these trimming functions are nice, they don't remove extraneous spaces from between words in the string. For example, if we had the string:

This is a test.

We might want to remove those extra between-word spaces, converting the string to:

This is a test


'****Start by trimming leading/trailing spaces
str = Trim(str)

'Now, while we have 2 consecutive spaces, replace them
'with a single space...
Do While InStr(1, str, " ")
str = Replace(str, " ", " ")
Loop

Or:

Spaces=" "
NumberOfSpaces=5
For i = 1 to NumberOfSpaces
Spaces = Spaces & " "
Do While InStr(1, str, Spaces)
str = Replace(str, " ", " ")
Loop
Next
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



All times are GMT -5. The time now is 02:43 AM.



Powered by: vBulletin Version 3.0.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
All content Copyright ©1999 - 2010, Programmers Resource, unless otherwise noted.