开发者

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 ?开发者_运维知识库


You can use

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜