Click here to Skip to main content
15,896,545 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
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

C#
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
Comments
Muthuraja Irullandi 17-Feb-13 8:58am    
Hi,
Could explain your condition to take those two words?
Joezer BH 17-Feb-13 9:18am    
Your question is unclear Gandi, please provide some more details.

try this code.hope it will help.
C#
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();

            }
 
Share this answer
 
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.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900