Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- myString = myString.Replace(" ", "")
- myString = myString.Trim()
- Imports System.Text.RegularExpressions
- Module TestRegExp
- Sub Main()
- ' Use to match all whitespace (note the lowercase s matters)
- Dim regWhitespace As New Regex("s")
- ' Use to match space characters only
- Dim regSpace As New Regex(" ")
- Dim testString As String = "First Line" + vbCrLf + _
- "Second line followed by 2 tabs" + vbTab + vbTab + _
- "End of tabs"
- Console.WriteLine("Test string :")
- Console.WriteLine(testString)
- Console.WriteLine("Replace all whitespace :")
- ' This prints the string on one line with no spacing at all
- Console.WriteLine(regWhitespace.Replace(testString, String.Empty))
- Console.WriteLine("Replace all spaces :")
- ' This removes spaces, but retains the tabs and new lines
- Console.WriteLine(regSpace.Replace(testString, String.Empty))
- Console.WriteLine("Press any key to finish")
- Console.ReadKey()
- End Sub
- End Module
- While ImageText1.Contains(" ") '2 spaces.
- ImageText1 = ImageText1.Replace(" ", " ") 'Replace with 1 space.
- End While
Add Comment
Please, Sign In to add comment