-
[RESOLVED] Commas
Say i have this in a textbox..
a b c d e
how do i have a commandbutton that will replace this into:
a, b, c, d, e
please keep in mind that there MAY be a space at the end of the e, or at the beginning of the a. also keep in mind i do NOT want it to show as ,a b, c, d, e, .... i want it as a, b, c, d, e .. how do i do this?
Thanks!!!!
-
Re: Commas
Try using Replace() function:
Code:
Debug.Print Replace("a b c d e", " ", ", ")
-
Re: Commas
Works great, but, like i said, there could be a space on the end of the e. Then, if i use your code and put a space at the end of the e, i get a comma at the end regardless of there being text or not at the end.
-
Re: Commas
So, check for last two characters and if you get ", " the use Left function:
Code:
mystring = "a b c d e "
mystring = Replace(mystring, " ", ", ")
If Right(mystring, 2) = ", " Then
mystring = Left(mystring, Len(mystring) - 2)
End If
-
Re: Commas
-
Re: Commas
Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer. Also if someone has been particularly helpful, or even particularly unhelpful, you have the ability to affect a their forum "reputation" by rating their post..