/
/
Enum SeperationMethod
Assignment
Tags
End Enum
Function ExtractVariable(ByVal InputString As String, ByVal variableToExtract As String, Optional ByVal sepMethod As SeperationMethod = SeperationMethod.Assignment)
Dim str As String = InputString
Dim file As String = My.Computer.FileSystem.GetTempFileName() & Rnd() * 999999 & ".xxx"
Dim final As String = ""
My.Computer.FileSystem.WriteAllText(file, str, False)
Dim reader As New IO.StreamReader(file)
While Not reader.EndOfStream
Dim curline As String = reader.ReadLine
If Not curline.Trim = vbNullString Then
If curline.Contains(variableToExtract) Then
If sepMethod = SeperationMethod.Assignment Then
Dim i1 As Integer = curline.IndexOf("=")
final = curline.Substring(i1 + 1)
Else
Dim i1 As Integer = curline.IndexOf("<" & variableToExtract & ">") + variableToExtract.Length + 3
Dim i2 As Integer = curline.IndexOf("</" & variableToExtract & ">", i1) + 1
final = Mid(curline, i1, i2 - i1)
End If
End If
End If
End While
reader.Dispose()
Return final
Try
My.Computer.FileSystem.DeleteFile(file, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently, FileIO.UICancelOption.DoNothing)
Catch ex As Exception
'MsgBox("Error Deleting Temporary File...")
End Try
End Function
Dim Str As String = "[Infos]" & vbCrLf & "Info1 = 10" & vbCrLf & "Info2 = 20" Dim extractedValue As String = ExtractVariable(Str, "Info1", SeperationMethod.Assignment)
Dim Str As String = "[Infos]" & vbCrLf & "<Info1>10</Info1>" & vbCrLf & "Info2 = 20" Dim extractedValue As String = ExtractVariable(Str, "Info1", SeperationMethod.Tags)





Dim file As String = My.Computer.FileSystem.GetTempFileName() & Rnd() * 999999 & ".xxx"
Dim final As String = "" My.Computer.FileSystem.WriteAllText(file, str, False) Dim reader As New IO.StreamReader(file)
While Not reader.EndOfStream
Dim curline As String = reader.ReadLine
If Not curline.Trim = vbNullString Then
If curline.Contains(variableToExtract) Then
If sepMethod = SeperationMethod.Assignment Then
Dim i1 As Integer = curline.IndexOf("=")
final = curline.Substring(i1 + 1)
Else
Dim i1 As Integer = curline.IndexOf("<" & variableToExtract & ">") + variableToExtract.Length + 3
Dim i2 As Integer = curline.IndexOf("</" & variableToExtract & ">", i1) + 1
final = Mid(curline, i1, i2 - i1)
End If
End If
End If
End While
reader.Dispose() Return final
