Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Guys,
Can you please give me suggestion of my problem,what should i do.Thanks in Advance.


I have a list of string containing expressions(begining with #:) and each expression may or may not have dbColumns.i want to get the dbColumns used in the Expression.
In Expression,only field names are presented after t(Dot) .

Below are Expressions

1)#:t.Brand (i want to get t.Brand)
2)#:iF(12 > 10,t.price,t.description) (i want to get t,price and t.description)
3)#:t.Brand + "and " + t.SubBrand (i want to get t.Brand and t.SubBrand)


I want to have a list of columns used in the above expression (As depicted below).So that i can compare these table columns fields with Database fields.

(t.Brand,
t.price,
t.description,
t.SubBrand)

Regards,
Aneeq
Posted
Updated 12-Nov-14 1:04am
v2
Comments
Tomas Takac 12-Nov-14 7:12am    
What did you try so far? Can you show us your code?
anik butt 12-Nov-14 7:21am    
i tried nothing yet,as i m not sure how to do that.
Mohammed Owais 12-Nov-14 7:15am    
Read this:
The 30 Minute Regex Tutorial[^]
Use Expresso Tool if you still Cant Figure out..
Exoresso Tool[^]
anik butt 12-Nov-14 7:19am    
i have already gone through it.. but not sure whether i should use Regex
Tomas Takac 12-Nov-14 7:23am    
You can do this with Regex. Do you have any particular problem?

Something like that should do the work:
C#
List<string> exp = new List<string>();

exp.Add("#:t.Brand");
exp.Add("#:iF(12 > 10,t.price,t.description)");
exp.Add("#:t.Brand + 'and ' + t.SubBrand");

System.Text.RegularExpressions.Regex searchTerm =
        new System.Text.RegularExpressions.Regex(@"t.\w+");

var qry = from al in exp
    let matches = searchTerm.Matches(al)
    where matches.Count>0
    select new
        {
            origText=al,
            foundText=from System.Text.RegularExpressions.Match match in matches
                            select match.Value
        };


Note: foundtext returns IEnumerable. So, you need to loop twice:
C#
foreach(var v in qry)
{
    Console.WriteLine("--- {0} ---", v.origText.ToString());
    foreach (var t in v.foundText)
    {
        Console.WriteLine("{0}", t.ToString());
    }
}



Result:
--- #:t.Brand ---
t.Brand
--- #:iF(12 > 10,t.price,t.description) ---
t.price
t.description
--- #:t.Brand + 'and ' + t.SubBrand ---
t.Brand
t.SubBrand
 
Share this answer
 
v3
Use a regex, but you are going to have to be a bit more "defined" about exactly what you want to get. Specifically, you need to define the start of your "match string" more accturately (does "(t.xxx" count? What about "(ant.xxx"? does that count? What decides?) and also the end - space? ")"? other characters?

So try samples with Expresso[^] until you are happy, then use the regex in a foreach loop in your code.

But you are probably going to want to look at more examples than those three to make sure you catch all cases.
 
Share this answer
 

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