Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,627 questions

56,915 answers

573 users

How to split string into words by spaces in VB.NET

3 Answers

0 votes
Imports System
				
Public Module Module1
	Public Sub Main()
		Dim s As String = "VB.NET Java Python PHP C#"
 
        Dim arr As String() = s.Split(New Char() {" "c})
 
        For Each word As String In arr
            Console.WriteLine(word)
        Next
	End Sub
End Module


' run:
'
' VB.NET
' Java
' Python
' PHP
' C#
'

 



answered Oct 24, 2018 by avibootz
edited Aug 29 by avibootz
0 votes
Imports System
Imports System.Text.RegularExpressions
Imports System.Collections.Generic

Module Module1

    Function SplitString(s As String, delims As String) As List(Of String)
        Dim parts = Regex.Split(s, delims)
        Dim tokens As New List(Of String)

        For Each p In parts
            If Not String.IsNullOrEmpty(p) Then
                tokens.Add(p)
            End If
        Next

        Return tokens
    End Function

    Sub Main()
	Dim s As String = "-c, c++.. c#:: -java ,php...python    vbnet"
        Dim delims As String = "[ ,.:\-!]+"

        Dim tokens = SplitString(s, delims)

        For Each t In tokens
            Console.WriteLine(t)
        Next
    End Sub

End Module



' run:
'
' c
' c++
' c#
' java
' php
' python
' vbnet
'

 



answered Aug 29 by avibootz
edited Aug 29 by avibootz
0 votes
Imports System
Imports System.Collections.Generic

Module Module1

    Function SplitString(s As String, delims As String) As List(Of String)
        Dim delimSet As New HashSet(Of Char)(delims)

        Dim normalized As New Text.StringBuilder()

        For Each ch As Char In s
            If delimSet.Contains(ch) Then
                normalized.Append(" "c)
            Else
                normalized.Append(ch)
            End If
        Next

        Dim parts() As String = normalized.ToString().Split(" "c)
        Dim tokens As New List(Of String)()

        For Each p As String In parts
            If p <> "" Then
                tokens.Add(p)
            End If
        Next

        Return tokens
    End Function

    Sub Main()
        Dim s As String = "-c, c++.. c#:: -java! ,php...python:      vbnet!"
        Dim delims As String = " ,.:\-!"

        Dim tokens As List(Of String) = SplitString(s, delims)

        For Each t As String In tokens
            Console.WriteLine(t)
        Next
    End Sub

End Module



' run:
'
' c
' c++
' c#
' java
' php
' python
' vbnet
'

 



answered Aug 29 by avibootz
...