Solved Replace multiple spaces (1 Viewer)

jack555

Member
Local time
Today, 20:34
Joined
Apr 20, 2020
Messages
93
Code:
Replace(me.txtName,"  "," ")
above code can be used to remove double spaces between two words in a string. However, if there are three or four spaces that randomly occurs, how can we strip all these extra spaces and keep only one space? Tried adding nested "replace" without success.

Any suggestions are welcome.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:34
Joined
May 7, 2009
Messages
19,237
Code:
me.txtName = Replace(me.txtName,"  "," ")
Do While Instr(1, Me.txtName, "  ") <> 0
    me.txtName = Replace(me.txtName,"  "," ")
Loop
 

jdraw

Super Moderator
Staff member
Local time
Today, 12:34
Joined
Jan 23, 2006
Messages
15,379
Depending on how many occurrences you anticipate, you could try

Replace(me.txtName," "," ",,9)

where 9 is >= the number of occurrences
 

Users who are viewing this thread

Top Bottom