Results 1 to 5 of 5

Thread: Parse a string into a list

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Parse a string into a list

    If I have a class file, and I load this class file into a string, what is the best way to extract all the functions and add each one of these functions into a list?

    I can do the old, search for word "Public Function", then search for "End Function" and then use a Mid statement to get the string and add the result to a list, but I am wondering if there is a regular expression code statement that can do this a lot easier.

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Parse a string into a list

    Yes, you could do this with a regex. In general, it would work fine. The only issue I see would be if you nest classes inside a class. All methods inside that nested class would get pulled out but you wouldn't know from the regex what class it was taken from. That means you'd have to write some logic to deal with nested classes and nested methods in nested classes.

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Parse a string into a list

    What about Private functions, Overrides, Overloads, Shadows ..... ?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Parse a string into a list

    depending on what you're trying to do, you could also use the CodeDom to compile it to a memory assembly, then use reflection on it to get at the public accessors to it (fields, properties, methods, functions)...

    Just a crazy thought.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Re: Parse a string into a list

    If I know the start of a string, and the end of a string (that occurs many times in a large string), what is the best way to get the contents between the two strings and add this contents to a List of String?

    E.g
    A large string contains many of the following:

    Code:
    <Compile Include="CommonActions.vb" />
        <Compile Include="Controller.vb" />
        <Compile Include="formAbout.designer.vb">
    I would like to get all the contents between the "" and add them to a List of String. In the above example, I would like the following:

    CommonActions.vb
    Controller.vb
    formAbout.designer.vb

    Is RegEx the best way to do this? If so, can I please have some example code to work with?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width