Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could use an enumerator but it's pretty much the same code just shorter.</p> <pre><code>Dim items = myList.Split(",").GetEnumerator If items.MoveNext Then FirstName = items.Current If items.MoveNext Then Address1 = items.Current If items.MoveNext Then Address2 = items.Current </code></pre> <p>It's pretty tough to validate coming from a comma delimited string.</p> <p>Of course if you are using objects you could pass something to your object and let your object parse it. I'm assuming you are able to use Linq in the next example. </p> <pre><code>Public Class Person Private Enum Position FirstName = 0 Address1 = 1 Address2 = 2 LastName = 3 End Enum Sub FillFromArray(ByVal Values() As String) FirstName = If(Values.ElementAtOrDefault(Position.FirstName), String.Empty) Address1 = If(Values.ElementAtOrDefault(Position.Address1), String.Empty) Address2 = If(Values.ElementAtOrDefault(Position.Address2), String.Empty) LastName = If(Values.ElementAtOrDefault(Position.LastName), String.Empty) End Sub Public FirstName As String Public Address1 As String Public Address2 As String Public LastName As String End Class Module MainModule Sub Main() Dim testString As String = "FirstName,Address 1,Address 2" Dim testPerson As New Person testPerson.FillFromArray(testString.Split(",")) Debug.Assert(testPerson.FirstName = "FirstName") Debug.Assert(testPerson.Address1 = "Address 1") Debug.Assert(testPerson.Address2 = "Address 2") Debug.Assert(testPerson.LastName = String.Empty) End Sub End Module </code></pre>
 

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