Click here to Skip to main content
12,358,863 members (64,245 online)
Rate this:
 
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 17-Feb-13 8:58am
   
Hi,
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
 
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


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