|
|
Title | Make a String extension method to replace spaces with non-breaking spaces in Visual Basic 2008 |
Description | This example shows how to make a String extension method to replace spaces with non-breaking spaces in Visual Basic 2008. |
Keywords | string, nbsp, extension method, Visual Basic 2008 |
Categories | Software 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 = " "
Return s.Replace(" ", space)
End Function
|
|
The program demonstrates this method with the following statement:
|
|
txtNbsp.Text = txtString.Text.SpaceToNbsp()
|
|
|
|
|
|