Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string

Status
Not open for further replies.

ggreg

Programmer
Mar 9, 2001
201
US
I have problems understanding Mid and len been working with
mid this afternoon but am not getting what I want,
what I need to do is take a string...like "0-8-6"
and all I want to do it take out the dashes so I will have
"086" some of my result have been " " and "8-6"
can someone help me

thanks in advance for any help!
 
If you have version 2000+, you could use the replace function:

[tt]strString = "0-8-6"
strString = replace(strString,"-","")
msgbox strString[/tt]

Search these fora with mid, instr, left, right, instrrev... and in the help files, there should be samples...

Roy-Vidar
 
that would be great for one but I got hundreds to do
 
Hi ggreg,

It always helps to give full details of what you want. Roy has given a good answer based on your question, but it seems it was the wrong question.

Where are your strings? In Word? Or Excel? Or somewhere else?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Hi ggreg,

Looks like we posted at the same time. That MS function does a lot more than just remove dashes but it will do the job - as would Roy's solution wrapped in a Function. Glad you're sorted anyway.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
greg, I'm assuming you are just using this as an example whilst learning VBA and not using this in anger, as if you were you would probably have just selected the lot in one go and done Edit / Replace / Replace what = '-' (Without the quotes), replace with = <blank> (ie just leave blank).

Regards
Ken..........

----------------------------------------------------------------------------
[peace]It's easier to beg forgiveness than ask permission[2thumbsup]
---------------- Click here to help the tsunami victims ----------------

 
yeah no anger just doing some hobbie stuff while trying
to keep my access exprience up! I use access at
work so I am always needing a function like I find at
Microsoft.com tell, it seem like i can never find
what i need in help or microsoft.com, i could not believe I stumble into what i needed
I thought about trying the find/replace but was not sure how to keep the numbers in while taking out the dashes, wouldn't using replace blank make the whole field blank?
Every thanks for commenting, now I am trying to figure out to tony's comment on how I could have wrapped that first response in a function, I knew there were many ways i could have done this.
Thanks all who commented I am sure this will help other people in the future!
 
To just fit the purpose:

[tt]Public Function rvsReplace(ByVal vstrIn as String) as String

rvsReplace = replace(strIn ,"-","")
End Function[/tt]

Call with for instance:
[tt]msgbox rvsReplace("0-8-6")[/tt]

- or to be a bit more generic

[tt]Public Function rvsReplace2(ByVal vstrIn as String, _
optional byval vstrReplace as string = "-" _
optional byval vstrReplaceWith as string = vbNullString) as String

rvsReplace2 = replace(strIn ,vstrReplace,vstrReplaceWith)
End Function[/tt]

Call with for instance
[tt]msgbox rvsReplace2("0-8-6") ' or
msgbox rvsReplace2("0-8-6","-","")[/tt]

or any other delimiter/replace by character(s).

Roy-Vidar
 
Argh - the typos... strIn within the function to be replaced with vstrIn [blush]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top