Toady Posted August 29, 2007 Share Posted August 29, 2007 (edited) I'm having difficulty in removing a comment from a line in VB. Here is an example line... Dim c As Char 'This is a comment Im trying to use regexp to erase the comment but have trouble with code lines that look like this.. Dim s As String = 'blah' ' 'This is a comment So this... StringRegExpReplace($fileArray[$i],"'.*","") Won't work for every case... any ideas? Edited August 29, 2007 by Toady www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding Link to comment Share on other sites More sharing options...
Xenobiologist Posted August 29, 2007 Share Posted August 29, 2007 Hi, sorry do not know vb. What kind of comments do exist? So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Toady Posted August 29, 2007 Author Share Posted August 29, 2007 A comment in VB starts with a ' character. Well I think i figured it out... I have to check wether its at end of string.. StringRegExpReplace($fileArray[$i],"'.*$","") www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding Link to comment Share on other sites More sharing options...
SadBunny Posted August 29, 2007 Share Posted August 29, 2007 I guess the first thing you need is a clear definition of what the exact algorithm for recognizing comments is (so you can distinguish them from strings etc). Are all your comments placed behind 1 ' and all your strings placed between two? (I.E. You never use apostrophes in comments themselves?) If so, then I would suggest to look for lines containing an UNeven number of apostrophes, because then you know that you have a comment in it, then just search from the right side of the string using StringInStr's fourth parameter. If you use apostrophes more loosely than that, it will be harder to tell comments apart from the actual code and you will need a more complex conceptual description of what exactly defines a comment, then when you know that exactly, you can 'translate' it to some RegEx query or a function or whatever you need. Examples of what I mean: how would you go about finding the comments in the following lines, if you use them like this? Dim s As String = 'blah' & 'blah' 'This is a comment Dim s As String = 'blah' & 'blah' 'This is a comment with an extra apostrophe at the end' Dim s As String = 'blah' & 'blah' 'This is a comment and it's a really good one Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Toady Posted August 29, 2007 Author Share Posted August 29, 2007 Well I believe I have found the solution... Since you can only comment code at the end of every line. Then the regular expressions would be "'.*$" This works for cases..Dim c as string = "string" 'CommentDim c as string = "string" 'Comment'Dim c as string = "string" 'Comment' something after comment www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding Link to comment Share on other sites More sharing options...
Xenobiologist Posted August 29, 2007 Share Posted August 29, 2007 Hi, and what do you do when the line is Dim s As String = 'blah' So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Toady Posted August 29, 2007 Author Share Posted August 29, 2007 (edited) No worry, you cant declare strings using those ', it has to be " Edited August 29, 2007 by Toady www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now