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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Trimming String

Status
Not open for further replies.

LuckyDuck528

Programmer
Dec 21, 2004
65
US
This should be pretty easy for some of you but I can't see to get it. I have some code that goes through every line in a file and looks for CreateObject("xxxxx.xxxxx"). What I need to do is pull out xxxxx.xxxxx The code I have below is returning [COLOR=red ]xxxxx.xxxxx") [/color]and I can't seem to get rid of the ") at the end.

All help is greatly appreciated. I have been driving myself nuts with this for a couple of days. Thank you immensily in advnced!

Code:
Dim qt
qt = Chr(34)
If Instr(1, strLine, "CreateObject", 1) Then
  k = InStr(1,strLine,"CreateObject",1)
  n = Instr(k+20,strLine, qt, 1) 
  strm = Mid(strLine, k+14,n)
  Wscript.Echo strm

more code...
 
How about...
Code:
Dim qt
qt = Chr(34)
If Instr(1, strLine, "CreateObject", 1) Then
  k = InStr(1,strLine,"CreateObject",1)
  n = InstrRev(k+20,strLine, qt, 1) 
  strm = Mid(strLine, k+14)
  strm = left(strline, n - 1)
  Wscript.Echo strm
 
Plain VB:
Code:
Dim lStartLoc As Long
Dim lEndLoc As Long
Dim strProjectClass As String

lStartLoc = InStr(strline, "CreateObject")
If lStartLoc Then
    'move up to first quote after CreateObject
    lStartLoc = InStr(lStartLoc, strline, Chr(34))
    
    'get position of next quote
    lEndLoc = InStr(lStartLoc + 1, strline, Chr(34))
    
    'the stuff we want is between the quotes
    strProjectClass = Mid(strline, lStartLoc + 1, (lEndLoc - lStartLoc) - 1)
End If

Debug.Print strProjectClass
 
If Instr(1, strLine, "CreateObject", 1) Then
strm = Split(Mid(strLine,InStr(1,strLine,"createobject",1)),"""")(1)
Wscript.Echo strm
' more code
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you so much! These were all excellent suggestions and I found what I was looking for!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top