Click here to Skip to main content
Rate this: bad
good
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
Comments
Muthuraja Irullandi at 17-Feb-13 8:58am
   
Hi,
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
good
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();
 
            }
  Permalink  
Rate this: bad
good
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.
  Permalink  
v2

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



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