-
Apr 26th, 2013, 01:17 AM
#1
Thread Starter
Frenzied Member
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.
-
Apr 26th, 2013, 10:14 AM
#2
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.
-
Apr 26th, 2013, 11:29 AM
#3
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!
-
Apr 26th, 2013, 01:03 PM
#4
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
-
Apr 26th, 2013, 11:16 PM
#5
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|