Manipulating strings with regular expression

I will have a different string type (the string will not have a fixed format, they will be different every time) from them I want to remove a certain substring. How can a string be

FUTIDX 26FEB2009 NIFTY 0
FUTSTK ONGC 27 Mar 2008
FUTIDX MINIFTY 30 Jul 2009
FUTIDX NIFTY 27 Aug 2009
NIFTY FUT XP: 29/05/2008

      

I want to remove the line that starts with FUT

. How can i do this?

+2


a source to share


2 answers


you can use



yourString = Regex.Replace(yourString, @"\bFUT\w*?\b", "");

      

+3


a source


Use Split by "tokenize" lines. Then check each substring if it starts with FUT .



string s = "FUTIDX 26FEB2009 NIFTY 0"
string[] words = s.Split(' ');
foreach (string word in words)
{
    if (word.StartsWith("FUT"))
    {
        //do something
    }
}

      

0


a source







All Articles