back up codes

always have a backup of your code

Archive for the tag “split”

split/join function

The Split Function returns an array containing a specified number of substrings.

The following code shows how to split strings


Dim TheString As String = "Hello World!"
Dim TheArray() As String = Split(TheString)
Dim a = TheArray(0)
Dim b = TheArray(1)

Data on a and b variables are Hello and World respectively.

The following code shows how to split strings with multiple delimiters in a row and filter out the empty strings.


Dim TheString As String = "me myself you "
Dim TheArray() As String = Split(TheString)
Dim NotEmpty As Integer = -1
For i As Integer = 0 To TheArray.Length - 1
If TheArray(i) "" Then
NotEmpty += 1
TheArray(NotEmpty) = TheArray(i)
End If
Next
ReDim Preserve TheArray(NotEmpty)
Dim a = TheArray(0)
Dim b = TheArray(1)
Dim c = TheArray(2)

Data on a,b and c variables are me, myself and you respectively.

Join Function returns a string joined from a number of substrings contained in an array.


Dim TheString() As String = {"me", "myself", "you"}
Dim JoinedList As String = Join(TheString, ", ")

The result is “me, myself, you”.

date split

The following code will split the given date entered and give the equivalent value on different dropdownlists.

First initialize the variables:

Dim thedate, mmddyyyy

Insert this code after getting data from database:

thedate = reader.Item("THE_DATE")
mmddyyyy = Split(thedate, "/")
ddlMonth.SelectedValue = mmddyyyy(0)
ddlDay.SelectedValue = mmddyyyy(1)
ddlYear.SelectedValue = mmddyyyy(2)

Post Navigation

Follow

Get every new post delivered to your Inbox.