How to get the second word of a string in VB.NET

3 Answers

0 votes
Imports System

Public Class GetTheSecondWordOfString_VB_NET
	Public Shared Sub Main()
		Dim str As String = "c java c# python c++ vb.net rust"
        Dim words As String() = str.Split(" "c)

        If words.Length > 1 Then
            Dim secondWord As String = words(1)
            Console.WriteLine("The second word is: " & secondWord)
        Else
            Console.WriteLine("The input string does not contain enough words.")
        End If
    End Sub
End Class


' run:
'
' The second word is: java
'

 



answered Oct 3, 2024 by avibootz
edited Oct 3, 2024 by avibootz
0 votes
Imports System
Imports System.Linq

Public Class Program
	Public Shared Sub Main()
		Dim str As String = "c java c# python c++ vb.net rust"
		
        Dim secondWord As String = str.Split(" "c).Skip(1).FirstOrDefault()
		
        Console.WriteLine(secondWord)
    End Sub
End Class



' run:
'
' java
'

 



answered Oct 3, 2024 by avibootz
0 votes
Imports System

Public Class Program
	Public Shared Sub Main()
		Dim str As String = "c java c# python c++ vb.net rust"
		
        Dim secondWord As String = str.Split(" "c)(1)
		
        Console.WriteLine(secondWord)
    End Sub
End Class



' run:
'
' java
'

 



answered Oct 3, 2024 by avibootz

Related questions

1 answer 118 views
1 answer 191 views
1 answer 125 views
1 answer 129 views
2 answers 194 views
...