Click here to Skip to main content
11,635,626 members (78,646 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
hello all

i am have string

string content = "Shoes|plant|tree|usek|setan|babi|anjing";

and I want to take two words, namely "Shoes | plant", in my search to write "shoes" only

string content = "Shoes|plant|tree|usek|setan|babi|anjing"
            string keyword = shoes;
            if (Regex.Match(content, @"\b" + keyword + @"\b", RegexOptions.Singleline | RegexOptions.IgnoreCase).Success)
                string result = Regex.Match(content, keyword + @"$",RegexOptions.None).ToString(); ;

the string result should be two words , namely "Shoes|plant"

how his code?
Posted 17-Feb-13 2:51am
Muthuraja Irullandi at 17-Feb-13 8:58am
Could explain your condition to take those two words?
Edo Tzumer at 17-Feb-13 9:18am
Your question is unclear Gandi, please provide some more details.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

try this code.hope it will help.
string content = "Shoes|plant|tree|usek|setan|babi|anjing";
            string keyword = @"^shoes\|plant";
            string result="";
            if (Regex.Match(content, keyword, RegexOptions.Singleline | RegexOptions.IgnoreCase).Success)
                result = Regex.Match(content, keyword, RegexOptions.Singleline | RegexOptions.IgnoreCase).ToString();
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Supposing you want the keyword and the word after it, use following expression: string pattern = String.Format("({0})\|\w+", keyword). And use this pattern as search pattern in the regular expression. The rest seems good.
This way you will find Shoes|plant for shoes, and usek|setan for usek whatever that means.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 8,861
1 Sergey Alexandrovich Kryukov 8,459
2 Mika Wendelius 6,849
3 F-ES Sitecore 2,354
4 Suvendu Shekhar Giri 2,270

Advertise | Privacy | Mobile
Web03 | 2.8.150728.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100