× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Find a particular string in an string array

Michael Perrenoud
Feb 06, 2015
<p>One approach would be to use a regular expression:</p> <pre><code>var regex = string.Format("Order\s*{0}\s*QTY", 1); int Quantity = Array.FindIndex(lineValues, x =&gt; Regex.Matches(x, regex)); </code></pre> <p>The regular expression I'd use would be something like this:</p> <pre><code>Order\s*1\s*QTY </code></pre> <p><img src="https://www.debuggex.com/i/1jCVIqj7pbBg7wpP.png" alt="Regular expression visualization"></p> <p><a href="https://www.debuggex.com/r/1jCVIqj7pbBg7wpP" rel="nofollow">Debuggex Demo</a></p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/26339410/Find%20a%20particular%20string%20in%20an%20string%20array/26339576">Stack Overflow</a>.</p>
comments powered by Disqus