.Split() Function

Am I using the .Split() function wrong? I have a DataGrid widget that returns the selected row. I am trying to parse the selected row string so I can access the values to display.

Here is a screenshot of how I am using it:

I am currently just sending the data to ErrorMessage.Text to view the output before I start setting it to my actual text boxes. The SelectedSKURow is my custom property string that my DataGrid SelectedRow is binded to. 

The SelectedRow returns "ID|Name|Qty1|Qty2" which is why I am trying to split by the "|" character. I originally had stringSplit = SelectedSKURow.Split("|") but that also wasn't splitting anything. It just sets the whole selected row string as stringSplit[1].

Parents
  • Here is a simpler version because why not? Slight smile

    dim MyString as string;
    MyString = "ID|Name|Qty1|Qty2";

    dim StringSplit[4] as string;
    StringSplit = MyString.Split("|".ToCharArray()[1]);

    LogMessage("value on position 1: "+StringSplit[1]);
    LogMessage("value on position 2: "+StringSplit[2]);
    LogMessage("value on position 3: "+StringSplit[3]);
    LogMessage("value on position 4: "+StringSplit[4]);

Reply
  • Here is a simpler version because why not? Slight smile

    dim MyString as string;
    MyString = "ID|Name|Qty1|Qty2";

    dim StringSplit[4] as string;
    StringSplit = MyString.Split("|".ToCharArray()[1]);

    LogMessage("value on position 1: "+StringSplit[1]);
    LogMessage("value on position 2: "+StringSplit[2]);
    LogMessage("value on position 3: "+StringSplit[3]);
    LogMessage("value on position 4: "+StringSplit[4]);

Children
  • If you lack forehand knowledge of the length of the resulting array, you can simply make an implicit declaration like this:.

    dim myArray = delimitedText.Split("|".ToCharArray());
     

    Building on Richard's example, something like this will likely work:

    dim s as string;
    for each s in delimitedText.Split("|".ToCharArray());
        LogMessage(s);
    end for;
    

    That said, myArray may turn out as a zero-indexed .NET array as opposed to the 1-indexed QuickScript arrays. Just because it would be too easy if they were just the same.