Dictionary<string,string> tags = new Dictionary<string,string>();
public string UpadeInput(String input)
{
tags.Add("DTI", "DT");
tags.Add("NNS", "NN");
tags.Add("LongAnnoyingTag", "ShortTag");
MatchEvaluator evaluator = new MatchEvaluator(ModifyTag);
return Regex.Replace(input,@"(?<=/)(?<firstMatch>[^\s]+)(?= )", evaluator);
}
public string ModifyTag(Match match)
{
return tags[match.Value];
}
Edit for composed tag.
You can just change the ModifyTag
method to work with different cases.
public string ModifyTag(Match match)
{
String tag = match.Value;
if(!tag.Contains("+"))
{
return tags[match.Value];
}
else
{
string[] composedTags = tag.Split('+');
return String.Format("{0}+{1}", tags[composedTags[0]], tags[composedTags[1]]);
}
}