Reputation: 41
I am trying like this:
int Quantity = Array.FindIndex(lineValues, x => x.Equals("Order 1 QTY"));
It is passing for the same string. But I want it to get passed even if there are no spaces between the string.
I want it to get passed with both the string:
"Order 1 QTY"
"Order1QTY"
I want to check for just string excluding spaces.
Upvotes: 0
Views: 109
Reputation: 1251
Alternatively, remove all the whitespace from your test string, then compare that to "Order1Qty".
int Quantity = Array.FindIndex(lineValues,
x => x.Replace(" ", "").Equals("Order1QTY"));
Upvotes: 0
Reputation: 67918
One approach would be to use a regular expression:
var regex = string.Format("Order\s*{0}\s*QTY", 1);
int Quantity = Array.FindIndex(lineValues, x => Regex.Matches(x, regex));
The regular expression I'd use would be something like this:
Order\s*1\s*QTY
Upvotes: 3
Reputation: 7929
You can do:
string y = "Order 1 QTY";
int Quantity = Array.FindIndex(lineValues, x => x.Equals(y) || x.Equals(y.Replace(" ","")));
Upvotes: 3