I want a functionality ,where user can enter some text in a textbox,and based on some predefined characters ,i have to identify different attributes user can be linked to.
For example : In the textbox user enters as:
“Hello @Sunil you are going to work on #Desktop which has a priority of !1”
Now from this data,i want to extract the name of the developer,i.e based on @..which is sunil.
name of the team based on # char,which is desktop..and priority of task,based on !char which is 1.
This data will be entered on a website,used for task management and admins will enter this…
So that then it becomes fast entry of tasks…for admins.
I can split the data and process it…but then there are too many permutations and combinations in which order chars(#,@,!) may be entered.
I tried something like this,but it didnt helped:
if (TitleText.Contains("#") && TitleText.Contains("@") && TitleText.Contains("!"))
{
string[] arr = TitleText.Split('#', '@', '!');
title = arr[0];
devName = arr[1].Trim().ToLower();
devTeam = arr[2].Trim().ToLower();
prio = Convert.ToInt32(arr[3]);
} else if (TitleText.Contains("#") && TitleText.Contains("@")) {
string[] arr = TitleText.Split('#', '@');
title = arr[0];
devName = arr[1].Trim().ToLower();
devTeam = arr[2].Trim().ToLower();
// prio = Convert.ToInt32(arr[3]);
} else if (TitleText.Contains("#") && TitleText.Contains("!")) {
string[] arr = TitleText.Split('#', '!');
title = arr[0];
devName = arr[1].Trim().ToLower();
//devTeam = arr[2];
prio = Convert.ToInt32(arr[2]);
} else if (TitleText.Contains("@") && TitleText.Contains("!")) {
string[] arr = TitleText.Split('@', '!');
title = arr[0];
// devName = arr[1];
devTeam = arr[1].Trim().ToLower();
prio = Convert.ToInt32(arr[2]);
} else if (TitleText.Contains("#")) {
string[] arr = TitleText.Split('#');
title = arr[0];
devName = arr[1].Trim().ToLower();
//devTeam = arr[1];
//prio = Convert.ToInt32(arr[2]);
} else if (TitleText.Contains("@")) {
string[] arr = TitleText.Split('@');
title = arr[0];
// devName = arr[1];
devTeam = arr[1].Trim().ToLower();
//prio = Convert.ToInt32(arr[2]);
} else if (TitleText.Contains("!")) {
string[] arr = TitleText.Split('!');
title = arr[0];
// devName = arr[1];
//devTeam = arr[1];
prio = Convert.ToInt32(arr[1]);
}
Try with regex