Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If the string is simply numbers separated by spaces I'd suggest going with <code>String.Split</code> method like this :</p> <pre><code>string[] mySerialNumbers = searchString.Split(new char[]{' '}); </code></pre> <p>See the documentation of <a href="http://msdn.microsoft.com/en-us/library/b873y76a.aspx" rel="nofollow">String.Split</a>. </p> <p>To have the result as an <code>IEnumerable</code> you can simply create a <code>List&lt;string&gt;</code> with the result of <code>String.Split</code> like this :</p> <pre><code>List&lt;string&gt; mySerialNumbers = new List&lt;string&gt;(searchString.Split(new char[]{' '}); </code></pre> <p>Edit:</p> <p>After reading the comment, the Regex way would indeed kind of validate the input to make sure no other characters are there, which is a good thing. The regex for this would be as simple as this :</p> <pre><code>foreach(Match match in Regex.Matches("1108656 1108657 1108658 1108659", "[0-9]{5,8}")) { // Do something with match.Value here like : int.Parse(match.Value) } </code></pre> <p>The regex expression [0-9]{5,8} means any digit repeated between 5 and 8 times. Of course this Regex is really simple and will simply capture the good things. For example as tring with 1234567 abcd 7654321 will not give any error, it will simply capture the 2 numbers and silently ignore the letters. You could make a much more complex regex to validate even better. This could be a solid starting reference for regex : <a href="http://www.mikesdotnetting.com/Article/46/CSharp-Regular-Expressions-Cheat-Sheet" rel="nofollow">http://www.mikesdotnetting.com/Article/46/CSharp-Regular-Expressions-Cheat-Sheet</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload