fork download
  1. Imports System
  2. Imports System.Text.RegularExpressions
  3. Imports System.Collections.Generic
  4.  
  5.  
  6. Public Class Test
  7. Public Shared Sub Main()
  8. Dim input As String = "ASD~QW~DFGH~LOP~GGGH~123~SXC~QL~"
  9.  
  10. Print(Split("asd"))
  11. Print(Split("asd~"))
  12. Print(Split("ASD~QW~DFGH~LOP~GGGH~123~SXC~QL~"))
  13. Print(Split("ASD~QW~DFGH~LOP~GGGH~123~SXC~QL~jones"))
  14. Console.WriteLine("....bye")
  15. End Sub
  16. Public Shared Sub Print(words As List(Of String))
  17. Console.WriteLine("Found {0} words", words.Count)
  18. For Each Val As String In words
  19. Console.Write(" [{0}]", Val)
  20. Next
  21. Console.WriteLine()
  22.  
  23. End Sub
  24. Public Shared Function Split(input As String) As List(Of String)
  25. Dim results = New List(Of String)
  26.  
  27. Dim pattern As String = ".*?~([^~]+?)(?=~)"
  28. Dim re As Regex = New Regex(pattern)
  29.  
  30. For Each mtch As Match In re.Matches(input)
  31. results.Add(mtch.Groups(1).Captures(0).Value)
  32. Next
  33. Return results
  34. End Function
  35. End Class
Success #stdin #stdout 0.14s 25920KB
stdin
Standard input is empty
stdout
Found 0 words

Found 0 words

Found 7 words
 [QW] [DFGH] [LOP] [GGGH] [123] [SXC] [QL]
Found 7 words
 [QW] [DFGH] [LOP] [GGGH] [123] [SXC] [QL]
....bye