Guest User

Untitled

a guest
Apr 24th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. myString = myString.Replace(" ", "")
  2.  
  3. myString = myString.Trim()
  4.  
  5. Imports System.Text.RegularExpressions
  6. Module TestRegExp
  7. Sub Main()
  8. ' Use to match all whitespace (note the lowercase s matters)
  9. Dim regWhitespace As New Regex("s")
  10.  
  11. ' Use to match space characters only
  12. Dim regSpace As New Regex(" ")
  13.  
  14. Dim testString As String = "First Line" + vbCrLf + _
  15. "Second line followed by 2 tabs" + vbTab + vbTab + _
  16. "End of tabs"
  17.  
  18. Console.WriteLine("Test string :")
  19. Console.WriteLine(testString)
  20.  
  21. Console.WriteLine("Replace all whitespace :")
  22. ' This prints the string on one line with no spacing at all
  23. Console.WriteLine(regWhitespace.Replace(testString, String.Empty))
  24.  
  25. Console.WriteLine("Replace all spaces :")
  26. ' This removes spaces, but retains the tabs and new lines
  27. Console.WriteLine(regSpace.Replace(testString, String.Empty))
  28.  
  29. Console.WriteLine("Press any key to finish")
  30. Console.ReadKey()
  31. End Sub
  32. End Module
  33.  
  34. While ImageText1.Contains(" ") '2 spaces.
  35. ImageText1 = ImageText1.Replace(" ", " ") 'Replace with 1 space.
  36. End While
Add Comment
Please, Sign In to add comment