Click here to Skip to main content
12,942,930 members (60,041 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 17-Feb-13 8:58am
Could explain your condition to take those two words?
Edo Tzumer 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
Top Experts
Last 24hrsThis month
OriginalGriff 4,633
CHill60 2,880
Maciej Los 2,268
Jochen Arndt 1,900
ppolymorphe 1,755

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2017
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