Search code examples
stringvb.netdesktop

vb.net code to divide the strings as required


I am totally new to string programing and trying to develop a program in VB.Net wherein I am unable to differentiate Students and Lecturers from a single Field.

Sample Data in Field TextBox1.Text= "1.(STU) KOLATI RAJA GOPAL , 2.(STU)MIRZA SHAFIULLAH BAIG , 3.(LEC)FAROOQ HUSSAI"

Desired Output

TextBox2.Text= "1.(STU) KOLATI RAJA GOPAL , 2.(STU)MIRZA SHAFIULLAH BAIG" //for students TextBox3.Text="3.(LEC)FAROOQ HUSSAI" //for Lecturers

Public FullPName As String
FullPName = UCase(TextBox1.Text)

 It1 = FullPName.IndexOf(SExe1)
 If It1 <> -1 Then
     For It1 = 0 To Len(FullPName - 1)
         Get1 = FullPName(It1)
     Next
 End If

Solution

  • Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        Dim aSTringArray() As String
    
        ' Split the string by commas, ignoring empties
        aSTringArray = TextBox1.Text.Split(CType(",", Char()), StringSplitOptions.RemoveEmptyEntries)
    
        For Each S In aSTringArray
    
            If S.Contains("STU") Then
    
                AppentTextbox(TextBox2, S)
    
            ElseIf S.Contains("LEC") Then
    
                AppentTextbox(TextBox3, S)
    
            End If
        Next
    
    End Sub
    
    Private Sub AppentTextbox(TB As TextBox, S As String)
    
        If TB.Text = "" Then
            TB.Text &= S
        Else
            TB.Text &= ", " & S
        End If
    
    End Sub
    

    End Class