Using the method String.Substring
, you can do it like this:
Dim texto As String = "if Argumento1 = Argumento2 ( --statements; );"
Dim ifIndice As Integer = texto.IndexOf("if")
Dim igualIndice As Integer = texto.IndexOf("=")
Dim ifLen As Integer = Len("if") + 1
Dim argumento1 As String = texto.Substring(ifIndice + ifLen, igualIndice - ifLen)
Dim argumento2 As String = texto.Substring(igualIndice + 2, texto.IndexOf(" (") - igualIndice - 1)
Console.WriteLine(String.Format("Arg1: {0}, Arg2: {1}", argumento1, argumento2))
Console.ReadLine()
Another way using regular expressions:
Imports System.Text.RegularExpressions
....
...
Dim texto As String = "if Argumento1 = Argumento2 ( --statements; );"
Dim argumento1 As String = "", argumento2 As String = ""
Dim match As Match = Regex.Match(texto, "if\s+([\w]+)\s+=\s+([\w]+)\s+\(", RegexOptions.IgnoreCase)
If match.Success Then
argumento1 = match.Groups(1).Value
argumento2 = match.Groups(2).Value
End If
Console.WriteLine(String.Format("Arg1: {0}, Arg2: {1}", argumento1, argumento2))
Console.ReadLine()
Whoa, whoa, thanks a lot ^-^.
– CypherPotato