Trying to split an array on a tab

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • AMP

    Trying to split an array on a tab

    Hello,
    I am trying to split an Array into another array. Each value in the
    array has tab delimited strings.
    I am getting:
    Cannot implicitly convert type 'string[]' to 'string'


    I am trying this:
    string[] lineSeparators = new String[]{"\r\n"};
    string[] Channel =
    FileName.Split( lineSeparators, StringSplitOpti ons.None); //This part
    works
    string[] Sample = new string[Channel.Length];
    string[] stringSeparator s = new String[] { "\t" };
    foreach (string ArrayString in Channel)


    {
    int i = 0;
    Sample[i] = ArrayString.Spl it(stringSepara tors,
    StringSplitOpti ons.None);
    i++;
    }

    Thanks
    Mike
  • Jon Skeet [C# MVP]

    #2
    Re: Trying to split an array on a tab

    On Mar 11, 4:32 pm, AMP <ampel...@gmail .comwrote:
    I am trying to split an Array into another array. Each value in the
    array has tab delimited strings.
    I am getting:
    Cannot implicitly convert type 'string[]' to 'string'
    And it's right. You've got

    string[] Sample

    which means that every element of Sample is a string.

    You're then trying:
    Sample[i] = ArrayString.Spl it(stringSepara tors,
    StringSplitOpti ons.None);

    (and then reinitializing i next time round the loop, by the way)

    string.Split returns an array of strings, not a single string - so you
    quite possibly want

    string[][] Sample = new string[Channel.Length][];

    However, I suspect there's a rather better way of doing this. Could
    you give an example of the input you've got, and the output you want?

    Jon

    Comment

    • AMP

      #3
      Re: Trying to split an array on a tab

      On Mar 11, 12:38 pm, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
      On Mar 11, 4:32 pm, AMP <ampel...@gmail .comwrote:
      >
      I am trying to split an Array into another array. Each value in the
      array has tab delimited strings.
      I am getting:
      Cannot implicitly convert type 'string[]' to 'string'
      >
      And it's right. You've got
      >
      string[] Sample
      >
      which means that every element of Sample is a string.
      >
      You're then trying:
      Sample[i] = ArrayString.Spl it(stringSepara tors,
      StringSplitOpti ons.None);
      >
      (and then reinitializing i next time round the loop, by the way)
      >
      string.Split returns an array of strings, not a single string - so you
      quite possibly want
      >
      string[][] Sample = new string[Channel.Length][];
      >
      However, I suspect there's a rather better way of doing this. Could
      you give an example of the input you've got, and the output you want?
      >
      Jon
      Jon,
      Its one long string.
      There are \r\n's at the end of rows and and \t's at the end of
      datapoints
      I want each row to be an Array by itself.

      3 1466 1462 1531 1465 1279 1490 1454 1441 1457 1453 1460 1459 1321
      1457 1443 1443 55
      75 1471 1469 1194 1467 2170 1491 1453 1442 1457 1455 1459 1460 2193
      1459 1443 1443 127
      148 1471 1472 1481 1463 1780 1490 1453 1442 1458 1455 1459 1459 1759
      1455 1444 1442 200
      220 1473 1470 1482 1465 843 1491 1453 1441 1458 1454 1459 1459 321
      1455 1443 1443 272
      293 1473 1480 1461 1465 1375 1486 1453 1443 1458 1455 1460 1459 1208
      1457 1443 1442 344
      365 1471 1472 1454 1463 1442 1490 1260 1446 1457 1456 1461 1460 1364
      1457 1444 1441 417
      438 1469 1459 1450 1460 1449 1489 2117 1444 1375 1455 1461 1459 1419
      1458 1444 1442 489
      510 1469 1463 1448 1460 1451 1491 1680 1443 2545 1463 1459 1460 1437
      1459 1445 1442 562
      582 1470 1466 1447 1459 1451 1489 1165 1435 1716 1454 1459 1460 1444
      1458 1445 1443 634
      655 1471 1478 1447 1461 1451 1489 1361 1440 483 1459 1459 1460 1447
      1457 1444 1442 707
      727 1469 1461 1447 1460 1452 1489 1420 1441 1004 1452 1458 1460 1448
      1457 1443 1443 779
      800 1468 1465 1447 1460 1453 1491 1441 1443 1313 1455 1460 1460 1448
      1457 1444 1443 851
      872 1462 1467 1447 1461 1454 1490 1449 1440 1407 1457 1461 1459 1448
      1457 1443 1442 924
      944 1462 1467 1446 1462 1454 1491 1451 1442 1439 1455 1460 1459 1449
      1456 1443 1441 996

      Thanks
      mike

      Comment

      Working...