Solved

Manipulating Strings

Posted on 2001-06-06
6
181 Views
Last Modified: 2010-05-02
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
Comment
Question by:bbaisley
6 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 6159503
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
 
LVL 1

Expert Comment

by:vbWayne
ID: 6159504
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
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6159597
Hi, you can also use the Replace function in VB 6.0
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 6159611
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6159714
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6159727
Ups!!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now