Thank you very much got your response.
I like the regex idea, but unfortunately I don't even know if what type of value I would get, I created a sample function below which is somehow is similar to what I want to achieve but the code is a bit long and the positions of the data array is fixed...
About regex, I need to study that because I never used its function before.
public class PatternVar
{
public string strPrefix;
public string strTable;
public string bInsert;
public string bReply;
public string strPattern;
}
public class InputExtract
{
public string dbTable;
public int patternNumber;
public string[] dbData;
}
public InputExtract SearchInputPattern(string inputPattern,List<patternvar> pVar,char delim)
{
InputExtract extractedData = new InputExtract();
extractedData.patternNumber = -1;
string sPrefix = inputPattern.Substring(0, 3);
foreach (PatternVar x in pVar)
{
if (x.strPrefix == sPrefix)
{
extractedData.dbTable = x.strTable;
extractedData.dbData = inputPattern.Remove(0,3).Split(delim);
extractedData.patternNumber = pVar.IndexOf(x);
break;
}
}
return extractedData;
}
public string DecodePattern(InputExtract InputExt, List<patternvar> pVar,char delim)
{
string DBCommand = "";
if (InputExt.patternNumber != -1)
{
if ((pVar[InputExt.patternNumber].bInsert == "Y")||(pVar[InputExt.patternNumber].bInsert == "y"))
{
DBCommand = "INSERT INTO " + InputExt.dbTable + " VALUES(";
for (int x = 0; x < InputExt.dbData.Length; x++)
{
DBCommand += InputExt.dbData[x] + ",";
}
DBCommand = DBCommand.Remove(DBCommand.Length - 1, 1);
DBCommand += ");";
}
else
{
string[] Headers = pVar[InputExt.patternNumber].strPattern.Split(delim);
DBCommand = "UPDATE " + InputExt.dbTable + " SET ";
for (int x = 1; x < InputExt.dbData.Length; x++)
{
DBCommand += Headers[x] + InputExt.dbData[x] + ",";
}
DBCommand = DBCommand.Remove(DBCommand.Length - 1, 1);
DBCommand += " WHERE " + Headers[0] + InputExt.dbData[0] + ";";
}
}
return DBCommand;
}
</patternvar></patternvar>
What I need is a simple few lines of command like your example... but I don't know how should it be done.
My idea is to create a function like:
string result = PatternMatch(string inputData, List<matchtable> mTable)
where
MatchTable{
string InputPattern;
string EquivalentPattern;
}
Any further suggestions?