How to remove the middle name from a full name in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
	Public Shared Sub Main()
        Dim name As String = "James John William"
		
        Console.WriteLine(name)
		
        Dim index1 As Integer = name.IndexOf(" ")
        Dim index2 As Integer = name.IndexOf(" ", index1 + 1)

        If index1 <> index2 AndAlso index1 >= 0 Then
            name = name.Remove(index1 + 1, index2 - index1)
            Console.WriteLine(name)
        End If
    End Sub
End Class



' run:
'
' James John William
' James William
'

 



answered Nov 23, 2021 by avibootz

Related questions

1 answer 171 views
1 answer 178 views
1 answer 215 views
1 answer 170 views
1 answer 233 views
...