'I want to compare a String that gets modified to its default
I am writing a method to exclude metafields from a .csv file.
public static string metaField(this string test)
{
String[] excludeMetafield = { "metafield_1000", "metafield_1001", "metafield_item_1_content_2", "metafield_short_description" };
String testing = "";
if (excludeMetafield.Contains(test) || excludeMetafield.Equals(test))
{
return test;
}
return testing = "Failed";
}
When the string test gets passed into the method it is for example "short_description" but when the value is written to the .csv file it gets modified to "metafield_short_description".
My .Contains is not detecting that "metafield_short_description" CONTAINS "short_description". How can I do this?
Solution 1:[1]
you can use linq
var excludeMetafield = new string[] { "metafield_1000", "metafield_1001", "metafield_item_1_content_2", "metafield_short_description" };
if (excludeMetafield.Any(e=>e.Contains(test))) return test;
return "Failed";
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Serge |
