How to split a string in half with VB.NET

2 Answers

0 votes
Imports System

Public Class Program
    Public Shared Sub Main(ByVal args As String())
        Dim str As String = "vb c java c++ python go"
        Dim center As Integer = str.Length / 2
        
		Dim parts As String() = New String() {str.Substring(0, center), str.Substring(center)}
		
        Console.WriteLine(parts(0))
        Console.WriteLine(parts(1))
    End Sub
End Class



' run:
'
' vb c java c+
' + python go
'

 



answered Aug 8, 2023 by avibootz
edited Aug 9, 2023 by avibootz
0 votes
Imports System

Public Class Program
	Public Shared Sub Main()
		Dim str As String = "vb.net c++ java c python go"
		
        Dim center As Integer = str.Length / 2
		
        Dim firstHalf As String = str.Substring(0, center)
        Dim secondHalf As String = str.Substring(center)
		
        Console.WriteLine(firstHalf)
        Console.WriteLine(secondHalf)
    End Sub
End Class



' run:
'
' vb.net c++ jav
' a c python go
'

 



answered Aug 8, 2023 by avibootz

Related questions

...