[Solved] How to read comment from .cpp file and display it into text box?


Do you want to remove all the / and * characters? There are several ways to do it, but a simple approach is replacing all the characters with an empty space and then trimming all the space later, here’s a sample code to start you with:

static void Main(string[] args)
{
    string text = System.IO.File.ReadAllText(@"C:\test.cpp");
    text = text.Replace("https://stackoverflow.com/", ' ');
    text = text.Replace('*', ' ');

    //Do all possible cleaning of text: text.Trim() etc...

    //Put text into text box (for now just display into console)
    Console.WriteLine(text);
    Console.ReadLine();
}

When you run the program make sure the test.cpp exists in your C:\ drive.

If you are just removing the /******/ beneath it, you can do the following instead:

string text = System.IO.File.ReadAllText(@"C:\test.cpp");
string[] lines = text.Split(new string[] { System.Environment.NewLine },
    StringSplitOptions.None);

//Gain control with each lines process as you wish, use StringBuilder etc.
for (int i = 0; i < lines.Length; i++ )
{
    Console.WriteLine(lines[i]);
}
Console.ReadLine();

2

solved How to read comment from .cpp file and display it into text box?