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
 
 
 
 
 
TitleMake a String extension method to replace spaces with non-breaking spaces in Visual Basic 2008
DescriptionThis example shows how to make a String extension method to replace spaces with non-breaking spaces in Visual Basic 2008.
Keywordsstring, nbsp, extension method, Visual Basic 2008
CategoriesSoftware Engineering, Strings
 
Thanks to By Michael Rosqvist.

This extension method adds a SpaceToNbsp method to the String class. It simply replaces occurrances of space characters with the " " HTML code for a non-breaking space.

 
<Extension()> _
Public Function SpaceToNbsp(ByVal s As String) As String
    Dim space As String = "&nbsp;"
    Return s.Replace(" ", space)
End Function
 
The program demonstrates this method with the following statement:
 
txtNbsp.Text = txtString.Text.SpaceToNbsp()
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated