I have a text file like this:
name=xyz
user=asdfjklas
etc...
i need to have a string called name with "xyz" in it, and a string called user with "asdfjlas" in it.
Can someone help me! I have spent like 4 hours on it already :( thanks!
Printable View
I have a text file like this:
name=xyz
user=asdfjklas
etc...
i need to have a string called name with "xyz" in it, and a string called user with "asdfjlas" in it.
Can someone help me! I have spent like 4 hours on it already :( thanks!
4 hours? Really? IO.File.ReadAllLines Store the result of that in a variable. Loop through each line in the array returned. Use some If logic to determine whether the line is indicating a Name or a User field. Then call String.Split on the line and retrieve the item at index 1, use the '=' char as the split parameter.
try this. i'm assuming you're using vb2008/10 as you haven't specified a version either in your profile or your thread:
vb Code:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim lines() As String = IO.File.ReadAllLines("yout textFile.txt") Dim name As String = lines.FirstOrDefault(Function(s) s.StartsWith("name")).Split("="c)(1) Dim user As String = lines.FirstOrDefault(Function(s) s.StartsWith("user")).Split("="c)(1) 'as requested End Sub End Class