locked
Matching Numbers in an Array RRS feed

  • Question

  • User1122355199 posted

     Hello Everyone and thanks for your help in advance.  I am working on an application that llops through a dataset.  Within each loop, I need to test to see if the datarow number is contained within an array.  For example:

    For Each Page in Pages

        Test to see if page number is found in array (i.e. page number = 3,  array = 1, 3, 4, 7, 8)

    Next Page

    The test would match on record numbers 1, 3, 4, 7, 8.

    I really can't seem to figure out a way to do this.  Any help would be greatly appreciated.

    Monday, January 10, 2011 9:14 PM

Answers

  • User-68639941 posted

    if you really want to store the values into single column and retrieve into array then you can store it as comma-separated values the use split function of string to get array from comma-separated string

    string[] values =  "1,2".Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

    hi,

     refer below code

    String[] values = { "One", "two", "three" };
      int index = Array.IndexOf(values, "three");
      if (index > -1)
      {
       // item found
       // your code
      }

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 10, 2011 10:53 PM

All replies

  • User-68639941 posted

    if you really want to store the values into single column and retrieve into array then you can store it as comma-separated values the use split function of string to get array from comma-separated string

    string[] values =  "1,2".Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

    hi,

     refer below code

    String[] values = { "One", "two", "three" };
      int index = Array.IndexOf(values, "three");
      if (index > -1)
      {
       // item found
       // your code
      }

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 10, 2011 10:53 PM
  • User1122355199 posted

    Thanks for the response.  Worked like a charm.  One other question if I may.  If I wanted to store the array values in a SQL Server table column, what owuld be the best way to do this and load it?  Maybe store the values in the column separated by commas, then parse the column to load the array?  Or is there a better way?

    Thansk again.

     

    Wednesday, January 12, 2011 7:54 PM