Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove a line from a string

Status
Not open for further replies.

BomberMan2K

Programmer
Sep 19, 2007
36
IL
Hi,
I'm building a very simple Whois client in c# and need to remove the non-relevant lines of response from the whois server.
Every comment-line is preceded by a "%" char and I want to remove the whole line.
I get the response into a string var - and would like to print it to a textbox without the comment lines.

How can this be accomplished?

Thank you,
Roman.
 
Hello,

Regular expressions will do the trick for you. The pattern below needs to be tweaked because it leaves a blank line when doing the replace. I apologize that I don't have time to do that tweak but hopefully this will at least get you started.
Code:
using System.Text.RegularExpressions; 

    string pattern = "^(\\s*%.*)"; 
    if (Regex.IsMatch(var, pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline)) { 
        var = Regex.Replace(var, pattern, string.Empty, RegexOptions.IgnoreCase | RegexOptions.Multiline); 
    }
If you have no other embedded double spaces then a work-around for the above problem would be to do something like this:
Code:
    var == var.replace(Constants.vbnewline + Constants.vbnewline, Constants.vbnewline)
Good Luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top