views:

64

answers:

2

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 ?

+3  A: 

You can use

yourString = Regex.Replace(yourString, @"\bFUT\w*?\b", "");
Jens
@Jens,Thanks for the answer,What I do is like there is a string like `FUTIDX 26FEB2009 NIFTY 0` Now I first remove the date from the string then I remove the string which starts from `FUT` with the help of your regex,and now remaining string is `NIFTY 0` But I want only `NIFTY`. It is only example but after removing date and removing string which starts with `FUT` from the remaining string I want only `NIFTY`.
Harikrishna
A: 

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
    }
}
PoweRoy