Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Please see the following code:

C#
List<string> ListOfGlobalTables = new List<string>();
string selectpart="SELECT Summary_New.ServiceName AS '[Q1].[ServiceName]'"


ListOfGlobalTables.Add("Summary");
ListOfGlobalTables.Add("Summary_New");

 foreach (string item in ListOfGlobalTables)
                {
                    string tableNamePlusDot = item + ".";

                    int count = Regex.Matches(selectpart, tableNamePlusDot).Count; 
                   
                  // just think what count should return
                  }


For the first item in the List, the following code return tableNamePlusDot as "Summary.".
C#
string tableNamePlusDot = item + ".";


After that the count should return 0 for the following code

C#
int count = Regex.Matches(selectpart, tableNamePlusDot).Count;

but it returns 1 !
Can anyone please help me to solve this problem ?
Posted

instead of adding '.' add
'\.'
to the pattern
 
Share this answer
 
v2
Comments
sachi Dash 22-Sep-15 2:58am    
Thanks a lot.
"." in a regex matched any character.
If you want to limit the search to "Summary" plus a dot, then:
C#
string tableNamePlusDot = item + @"\.";
Should fix it.
 
Share this answer
 
Comments
Matt T Heffron 21-Sep-15 12:33pm    
The backslash in the quoted string doesn't get displayed!
So, to clarify for sachi:
the string to append to the item contains 2 characters, a backslash and a dot.
The initial @ should prevent the backslash from being treated as a quoting prefix.
OriginalGriff 21-Sep-15 12:49pm    
I am getting well and truly fed up with MarkUp... :sigh:
sachi Dash 22-Sep-15 2:57am    
Thanks everyone the code should be
string tableNamePlusDot = item + @"\.";

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