Advertisement
filmee24

FunctionParsing

Jan 7th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.53 KB | None | 0 0
  1. Imports System.ComponentModel
  2. Imports System.Text
  3.  
  4. <DefaultEvent("Parsed")>
  5. Public Class Engine
  6.     Inherits Component
  7.  
  8.     Public Event Parsed(item As Item)
  9.  
  10.     Public Function Parse(s As String) As Item
  11.         Dim it As New Item()
  12.  
  13.         it.Name = s.Split("(")(0)
  14.         Dim arglist As String = Middle(s, "(", ")")
  15.  
  16.         If arglist.Contains(",") Then
  17.             Dim spl As String() = arglist.Split(",")
  18.             For Each Itm In spl
  19.                 it.Arguments.Add(Itm)
  20.             Next
  21.         Else
  22.             it.Arguments.Add(arglist)
  23.         End If
  24.  
  25.         RaiseEvent Parsed(it)
  26.  
  27.         Return it
  28.     End Function
  29.  
  30.  
  31.     Public Class Item
  32.         Public Property Name As String
  33.         Public Property Value As String
  34.         Public Property Arguments As New List(Of String)
  35.  
  36.         Public Function ArgToString() As String
  37.             Dim result As New StringBuilder
  38.             For Each l In Arguments
  39.                 result.Append(l & ",")
  40.             Next
  41.             Dim returns As String = result.ToString
  42.             If returns.EndsWith(",") Then
  43.                 returns = returns.Remove(returns.Length - 1, 1)
  44.             End If
  45.             Return returns
  46.         End Function
  47.     End Class
  48.  
  49.     Public Function Middle(str As [String], startchar As String, endchar As String) As String
  50.         Dim strStart As String = str.IndexOf(startchar) + 1
  51.         Dim strEnd As Integer = str.LastIndexOf(endchar)
  52.         Return str.Substring(strStart, strEnd - strStart)
  53.     End Function
  54. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement