Split a string into an array on space OR carriage return

D

Dave

Greetings,

Is there a way I can split a string into an array on a space OR a carriage
return? What would the code look like for this?

Thanks,

-Dave
 
J

José Joye

Try.... String.Split() // the one with the array param if you want to split
on space OR CR

- José
 
C

Chris, Master of All Things Insignificant

Direct form MSDN Help on String.Split

Imports System
Imports Microsoft.VisualBasic
_

Public Class StringSplit2

Public Shared Sub Main()

Dim delimStr As String = " ,.:"
Dim delimiter As Char() = delimStr.ToCharArray()
Dim words As String = "one two,three:four."
Dim split As String() = Nothing

Console.WriteLine("The delimiters are -{0}-", delimStr)
Dim x As Integer
For x = 1 To 5
split = words.Split(delimiter, x)
Console.WriteLine(ControlChars.Cr + "count = {0,2} ..............",
x)
Dim s As String
For Each s In split
Console.WriteLine("-{0}-", s)
Next s
Next x
End Sub 'Main
End Class 'StringSplit2

Hope it helps
Chris
 
H

Herfried K. Wagner [MVP]

Dave said:
Is there a way I can split a string into an array on a space OR a carriage
return? What would the code look like for this?

\\\
Dim s As String = ...
Dim astr() As String = s.Split(ControlChars.Cr, " "c)
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top