Reputation: 1351
I have this value
public static Dictionary<string, string> projectCustomerNameMapping = new Dictionary<string, string>()
{
{"Diooiio","Oppo" }
{"SSoois","RealMe"}
};
which I am reading like this
if( !projectCustomerNameMapping.TryGetValue( (string)data["Project"], out customerName ) )
{
// if the value wasn't found in the dictionary, use the default
customerName = "OnePlus";
}
My question is above it actually matches the Project and then gives the customerName, but I would like if it contains a value from project it should return the customer name. so if my project has value as "PoC_Diooiio" or "Diooiio" or anything which contains "Diooiio" it should give me customer name "Oppo". How do I fix it?
Upvotes: 0
Views: 156
Reputation: 1728
string search = data["Project"];
var customerName = projectCustomerNameMapping
.FirstOrDefault(q => q.Key.IndexOf(search ) != -1 || search.IndexOf(q.Key) != -1)
.Value ?? "OnePlus";
Upvotes: 1
Reputation: 216
string temp = "Diooiio";
if(customerName.contains(temp) == true)
{
customerName = projectCustomerNameMapping[temp];
}
You may loop through all the elements of Dictionary for rest.
Upvotes: 0
Reputation: 11
Why don't you try using Linq. The below will return a Like resultset for you.
This is just a guide for your code. It will return the first response it finds, if there is one, and may not always be the one you want.
If it finds nothing, it will return "OPPO"
public string findCustomerName(string input)
{
var result = projectCustomerNameMapping.FirstOrDefault(x => x.Key.Contains(input));
if (result.Key == null)
return "OPPO";
else
return result.Value;
}
Upvotes: 1