Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

Manipulating Strings

I have a string that is rather large (4 printed pages). In it, there are methods that I need to extract. They all start with either "procedure" or "function", followed by a name, and then the body.

What I need to do, is search the entire string for the types (function/procedure) and copy that to a variable, then take the name and copy that to a variable, and then take the body and copy that as well.

There is usually more then one method in this string.

How would be the best way to do this?
Thanks!
0
bbaisley
Asked:
bbaisley
1 Solution
 
deightonCommented:
You need to use the instr function

set the start parameter to the end of the section you last found, or 1 if you are searching for the first time
0
 
vbWayneCommented:
split function

an example of the string would help in giving a better answer...even a condensed version
ie.
function myname bla bla
bla bla
bla
procedure myname bla bla
etc...
One would need to see the string.
0
 
Ryan ChongCommented:
Hi, you can also use the Replace function in VB 6.0
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
dim strTEXT as string
dim strLines() as string

dim strMethodName as string
dim strMethodBody as string

dim lngLoop as Long

'i assume that strText is the variable that holds the whole text...

strLines = split(strText, vbCrLf)
for lngLoop = lbound(strLines) to ubound(strLines)
  select case true
  case strLines(lngLoop) like 'PROCEDURE *', strLines(lngLoop) like 'FUNCTION *'
    'the last procedure/function has ended:
    Debug.Print strMethodName, strMethodBody

    'here begins a new procedure/function
    strMethodName = Mid(strLines(lngLoop), Instr(1,strLines," "))
    strMedthodBody = ""

  case else
    strMethodBody = strMethodBody & strLines(lngLoop) & cvcrlf
  end select

next

'the last procedure/function has ended:
Debug.Print strMethodName, strMethodBody


Now instead of the DEBUG.PRINT, you can do something else with the strMethodName and Body...

Cheers


0
 
Richie_SimonettiCommented:
We need how the procedure finishes..., i.e., with end sub or end procedure or whatever.
Well, you could try with instr function.
1).- Save the contents of complete file to a string variable.
2).- Create a procedure like this:

Option Explicit
Dim vars() As String
Sub SearchText(sTargetStr As String, sStartText2Search As String, sEndText2Search)
Erase vars
Dim i As Long ' just for sure
Dim sStartPos As Long, sEndPos As Long

sStartPos = 1
Do
    sStartPos = InStr(1, sTargetStr, sStartText2Search, vbTextCompare)
'    Debug.Print sTargetStr
    If sStartPos = 0 Then Exit Sub
    sEndPos = InStr(sStartPos, sTargetStr, sEndText2Search, vbTextCompare)
    ReDim Preserve vars(i)
    vars(i) = Mid$(sTargetStr, sStartPos, (sEndPos - sStartPos) + Len(sEndText2Search))
    i = i + 1
    ' compress sTargetStr
    sTargetStr = Mid$(sTargetStr, sEndPos + Len(sEndText2Search))
Loop Until sStartPos = 0


End Sub

Private Sub Form_Click()
Dim i As Long
Dim str As String

Open "D:\Backup\API Examples\get_dsktop_win.frm" For Input As #1
    str = Input(LOF(1), 1)
Close #1
SearchText str, "function", "long"
For i = 0 To UBound(vars)
    Me.Print vars(i)
Next i

End Sub



NOTE: there is not a complete example but i think you could figure out
0
 
Richie_SimonettiCommented:
Ups!!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now