i'm having event in different name for different provider so i need help to post the exact match of the event that is
string parsing or some other method to do this please anyone reply me as soon as possible.
Example:
I)Poland vs Greece,Poland v Greece
II)Republic of Ireland vs Croatia,Ireland v Croatia,Ireland L1 v Croatia L2
III) Ukraine vs Sweden,Ukraine v Sweden,Ukraine X1 V Sweden X2
IV) New York Team L VS California public Team X2,New York V California,New York Team VS California X2
Please any one help me to solve this issue
Thank You
Regards,
Deepan
VulpesPosted Jun 6, 2012, 6:29 AM
One thing that's easy is to get 'versus' onto a common basis.
Suppose 'v' is the common basis and the other possibilities are : vs, V and VS.
Then a simple regular expression can change all of these to 'v'.
Similarly, if you decide that stuff like L, L1, L2, X1, X2, Team and public is unnecessary, then you can easily get rid of them using another regular expression.
A potentially more difficult problem is to replace stuff such as Republic of Ireland with just Ireland though this particular case, of course, presents no problem.
Anyway, here's a simple program to show how you can reduce all those strings to a common basis using regular expressions:
using System;
using System.Text.RegularExpressions;
class Test
{
static void Main()
{
string[] games =
{
"Poland vs Greece",
"Poland v Greece",
"Republic of Ireland vs Croatia",
"Ireland v Croatia",
"Ireland L1 v Croatia L2",
"Ukraine vs Sweden",
"Ukraine v Sweden",
"Ukraine X1 V Sweden X2",
"New York Team L VS California public Team X2",
"New York V California",
"New York Team VS California X2"
};
string regExp = " (vs|V|VS) ";
string regExp2 = @"\b(L|L1|L2|X1|X2|Team|public)( |$)";
string regExp3 = "Republic of ";
for(int i = 0; i < games.Length; i++)
{
games[i] = Regex.Replace(games[i], regExp, " v ");
games[i] = Regex.Replace(games[i], regExp2, "").TrimEnd();
games[i] = Regex.Replace(games[i], regExp3, "");
}
// check it worked:
foreach(string game in games) Console.WriteLine(game);
Console.ReadKey();
}
}
The console output should be:
Poland v Greece
Poland v Greece
Ireland v Croatia
Ireland v Croatia
Ireland v Croatia
Ukraine v Sweden
Ukraine v Sweden
Ukraine v Sweden
New York v California
New York v California
New York v California