dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: [RESOLVED] Visual Studio Regex Replace Line That Starts WIth A Letter.

  1. #1
    Join Date
    Jul 2017
    Posts
    86

    [RESOLVED] Visual Studio Regex Replace Line That Starts WIth A Letter.

    Hello!

    I have something like this with thousands of comments (#)

    Code:
    # The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the
    # initial value of a variable or macro / define can have for it to appear in the
    # documentation. If the initializer consists of more lines than specified here
    # it will be hidden. Use a value of 0 to hide initializers completely. The
    # appearance of the value of individual variables and macros / defines can be
    # controlled using \showinitializer or \hideinitializer command in the
    # documentation regardless of this setting.
    # Minimum value: 0, maximum value: 10000, default value: 30.
    
    MAX_INITIALIZER_LINES  = 30
    
    # Set the SHOW_USED_FILES tag to NO to disable the list of files generated at
    # the bottom of the documentation of classes and structs. If set to YES, the
    # list will mention the files that were used to generate the documentation.
    # The default value is: YES.
    
    SHOW_USED_FILES        = YES
    
    # Set the SHOW_FILES tag to NO to disable the generation of the Files page. This
    # will remove the Files entry from the Quick Index and from the Folder Tree View
    # (if specified).
    # The default value is: YES.
    
    SHOW_FILES             = YES
    
    # Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces
    # page. This will remove the Namespaces entry from the Quick Index and from the
    # Folder Tree View (if specified).
    # The default value is: YES.
    
    SHOW_NAMESPACES        = YES
    
    # The FILE_VERSION_FILTER tag can be used to specify a program or script that
    # doxygen should invoke to get the current version for each file (typically from
    # the version control system). Doxygen will invoke the program by executing (via
    # popen()) the command command input-file, where command is the value of the
    # FILE_VERSION_FILTER tag, and input-file is the name of an input file provided
    # by doxygen. Whatever the program writes to standard output is used as the file
    # version. For an example see the documentation.
    
    FILE_VERSION_FILTER    =
    
    # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
    # by doxygen. The layout file controls the global structure of the generated
    # output files in an output format independent way. To create the layout file
    # that represents doxygen's defaults, run doxygen with the -l option. You can
    # optionally specify a file name after the option, if omitted DoxygenLayout.xml
    # will be used as the name of the layout file.
    #
    # Note that if you run doxygen from a directory containing a file called
    # DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE
    # tag is left empty.
    
    LAYOUT_FILE            =
    
    # The CITE_BIB_FILES tag can be used to specify one or more bib files containing
    # the reference definitions. This must be a list of .bib files. The .bib
    # extension is automatically appended if omitted. This requires the bibtex tool
    # to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info.
    # For LaTeX the style of the bibliography can be controlled using
    # LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the
    # search path. See also \cite for info how to create references.
    
    CITE_BIB_FILES         =
    I want to remove all the lines that start with the character #. I'm new in regular expresions and I can't find a way of doing this even after I read Visual Studio, using regular expressions

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,669

    Re: Visual Studio Regex Replace Line That Starts WIth A Letter.

    I can't help with regex, but as you have asked this question in a c++ forum, a possible c++ code solution would be:

    Code:
    #include <fstream>
    #include <iostream>
    #include <string>
    #include <cstring>
    #include <vector>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
    	if (argc != 3)
    		return cerr <<"Format is:\n" << argv[0] << " infilename outfilename\n", 1;
    
    	if (!strcmp(argv[1], argv[2]))
    		return cerr << "Input file name and output file name must be different\n", 2;
    
    	ifstream ifs(argv[1]);
    
    	if (!ifs.is_open())
    		return cerr << "Cannot open input file " << argv[1] << endl, 3;
    
    	ofstream ofs(argv[2]);
    
    	if (!ofs.is_open())
    		return cerr << "Cannot open output file " << argv[2] << endl, 4;
    
    	for (string line; getline(ifs, line); )
    		if (!line.empty() && (line.front() != '#'))
    			ofs << line << "\n";
    }
    This takes 2 arguments as file names. The first is the input file containing the comments and the second is the output file without the comments. Given the sample in post #1 as file comm.txt,

    Code:
    c:\MyProgs>test12 comm.txt comm1.txt
    
    c:\MyProgs>type comm1.txt
    MAX_INITIALIZER_LINES  = 30
    SHOW_USED_FILES        = YES
    SHOW_FILES             = YES
    SHOW_NAMESPACES        = YES
    FILE_VERSION_FILTER    =
    LAYOUT_FILE            =
    CITE_BIB_FILES         =
    comm1.txt contains the input less the lines starting with #.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.0.4)

  3. #3
    Join Date
    Jul 2017
    Posts
    86

    Re: Visual Studio Regex Replace Line That Starts WIth A Letter.

    Sorry, I thought because these topics are about visual c++, it would be a good place to ask about visual studio. Anyway, creating your own program to do that (as you mentioned) seems a good solution (I'm such a fan of VS that I didn't thought of creating my own program that does what i want). But if someone else know's how to do that using visual studio I would like to know.

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,669

    Re: Visual Studio Regex Replace Line That Starts WIth A Letter.

    it would be a good place to ask about visual studio.
    What language are you using?

    c, c++, c++/cli, c#, f#, vb.net - other?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.0.4)

  5. #5
    Join Date
    Jul 2017
    Posts
    86

    Re: Visual Studio Regex Replace Line That Starts WIth A Letter.

    Quote Originally Posted by 2kaud View Post
    What language are you using?

    c, c++, c++/cli, c#, f#, vb.net - other?
    c++

    I also found the solution I was looking for (below is the regular expression):
    Code:
    #.*.*
    This will replace any text that starts with # and contains any other character except the new line.
    The last asterisk means that if there is text that contains only # and nothing else, take it into account too.

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)