Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Does the string end in a comma, like the example string that you put up?</p> <p>Cause if that is the case, that's your problem right there.</p> <p>Your first split then creates an array with 3 indexes</p> <pre><code>{"Domain\X_User|X_User", "Domain\Y_User|Y_User", ""} </code></pre> <p>(Note the empty string in index 2)</p> <p>If you then going to loop the array you go through it 3 times, the splits there work just fine for index 0 and 1, resulting in {"Domain\X_User", "X_User"} and {"Domain\Y_User", "Y_User"}, but splitting the 3rd index, the result of your split is an empty array.</p> <p>When you try to retrieve the 2nd index of the NamesArr array, it'll result in an IndexOutOfRangeExeption.</p> <p>You better ad some kind of check within the loop to make sure you can actually split your value:</p> <pre><code>Public Function SubString_Owner(X As String) As String Dim OwnerArray() As String = Split(X, ",") Dim Names As String Dim i As Integer = 0 While i &lt;= OwnerArray.Length - 1 If Not String.IsNullOrEmpty(OwnerArray(i)) AndAlso OwnerArray(i).Contains("|") Then Dim NamesArr As String() = Split(OwnerArray(i), "|") Names &amp;= NamesArr(1) &amp; "," End If i += 1 End While Return Names End Function </code></pre> <p>I'm doing 2 checks here, the first to make sure that the provided value isn't Nothing (null) and the 2nd to see if it contains the needed "|" to split it. The 2nd statement would give a NullReference error if the value would be Nothing.</p> <p>Also note that I edited the line</p> <pre><code>Names = NamesArr(1) + "," </code></pre> <p>into</p> <pre><code>Names &amp;= NamesArr(1) &amp; "," </code></pre> <p>Your statement would overwrite Names with every loop and you would only return the last username. Also to concatenate string in VB.NET, you should use "&amp;" instead of "+"</p> <p>Oh and why haven't you used a FOR loop? It's more readable than a While loop and therefor preferred in this case.</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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