Harikrishna
Harikrishna

Reputation: 4305

String Manipulation with Regex

I will have a different type of string(string will not have fixed format,they will be different every time) from them I want to remove some specific substring.Like the string can 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 string which starts with FUT. How can I do that ?

Upvotes: 2

Views: 448

Answers (2)

RvdK
RvdK

Reputation: 19790

Use Split to 'tokenize' the strings. 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
    }
}

Upvotes: 0

Jens
Jens

Reputation: 25563

You can use

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

Upvotes: 3

Related Questions