Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
  Tip: Use the Split function easily in Visual Basic .NET  
 
 

Thanks to Michael Rosqvist. Michael says:

If you add this module to a project:

Public Module Strings
  Public Split As Func(Of String, String()) = _
    Function(T As String) T.Split(New String() _
    {",", " ", "."}, StringSplitOptions.RemoveEmptyEntries)
End Module

You can then write code like this:

Public Module Main
  Sub Main()
    Dim sq As String = "Vestibulum a elit . Morbi risus sem, imperdiet et, laoreet sed, placerat id, mauris. "
    Array.ForEach(Split(sq), Function(s As String) Wrajt(s))
    Console.ReadLine()
  End Sub
  Private Function Wrajt(ByRef s As String) As Boolean
    Console.WriteLine(s)
    Return True
  End Function
End Module

The benefit here is all split logic is in one place.

Another benefit is that you cannot call Microsoft.VisualBasic.Strings.Split using Strings.Split.

 

Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated