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!

EX way to search strings 4

Status
Not open for further replies.

Japskunk72

Programmer
Feb 19, 2003
64
US
I want to search a string to see if it contains a ".". I want to count how many charecters from the right it is also.
is there a command that will look at a string and see if the charecter is there and return its placing?

Thanks for the help.
JT
 
Code:
Dim StringToSearch As String
StringToSearch = "I need help."
Debug.Print InStr(StringToSearch, ".")

This returns the value 12.

Hope it helps.

Harold

***You can't change your past, but you can change your future***
 


>I want to count how many charecters from the right it is also

Look up InsStrRev

Good Luck

 
> Look up InsStrRev

Sorry, but that's InStrRev.

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"A computer program does what you tell it to do, not what you want it to do." -- Greer's Third Law
 
You ain't seen me playing Enamy Territory... I'd probably miss and shoot myself!

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"A computer program does what you tell it to do, not what you want it to do." -- Greer's Third Law
 
He did say right, didn't he? I must have been looking from behind the monitor. hmmm....



***You can't change your past, but you can change your future***
 
wraygun

You've got a real cool monitor if it's see-through!

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"A computer program does what you tell it to do, not what you want it to do." -- Greer's Third Law
 

Japskunk72,

Was any of this helpful to you???

As we can see by your profile that you have only replied in 11 out of 21 of your threads and you have marked 7 of those with stars.

Please Read FAQ222-2244

and whether you use InStr or InStrRev you will also need to know about Len ...
Dim CharsFromLeft As Integer, CharsFromRight As Integer, S As String
S = "This is a test. This is only a test. Remember, this is just a test."
CharsFromLeft = InStr(1, S, ".")
CharsFromRight = Len(S) - CharsFromLeft
'or
CharsFromLeft = InStrRev(S, ".")
CharsFromRight = Len(S) - CharsFromLeft'0
[/tt]

Good Luck

 
Did he tell he has multiple "." s in the source string?
 
Yeah after reading the responses I reviewed Instr and InstrRev and decided that not what i wanted to go with. they where good answers and sorry for not posting a star. I decedided to use FSO's getextensionname instead. I was running a loop before to try and find the period for an extention but from researching the web i found info on how to get what i needed with one command.

Function GetExtention()
Dim FSO As New FileSystemObject
EXT = FSO.GetExtensionName(FilePath)
End Function
 
Thanks for the star.

It would have helped if you had told us that you wanted to extract the extension from a filename. You'd've got a useful answer much quicker.

Might I also point out that the code you posted won't work?
Code:
Public Function GetExtension(strPath) As String
  Dim fsoX As Scripting.FileSystemObject

  Set fsoX = New Scripting.FileSystemObject
  GetExtension = fsoX.GetExtensionName(strPath)
  Set fsoX = Nothing
End Function

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"A computer program does what you tell it to do, not what you want it to do." -- Greer's Third Law
 

Japskunk72,

Cool, glad you got it worked out but if we knew that it was the extension of a path filename you were looking for then...
[tt]
Dim Ext As String, S As String

S = "C:\somedirectory\somefile.txt"

Ext = Mid(S, InStrRev(S, ".") + 1)
[/tt]

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top