Changing an element in an array
I am trying to read a comma delimited text file to an array, then change just one element in the array and write it back to the text file. An example of what the text file would look like is:
data1,data2,data3
data1,data2,data3
data1,data2,data3
I want to change data in the last line at the last postion , data3, for example.
I am reading the file in with no problem. Im stuck on how to change the data and write it back to the text file.
Im a noob and any help would be a greatly appreciated! thanks!
Re: Changing an element in an array
You change the data simply by assigning a new value to the appropriate element by index. As for writing the data back out, use a StreamWriter inside nested For loops.
Re: Changing an element in an array
I understand using StreamWriter, but how do I assign by index?
I am reading into the array something like this:
For i As Integer = 0 To n
line = bagfile(i)
data = line.Split(","c)
equipment(i).item = data(0)
equipment(i).value = data(1)
equipment(i).equiped = data(2)
would I do something like equipment(i).item = "some value" ?
Again, I am a noob, sorry if this seems really basic..
Re: Changing an element in an array
Did that work when you tried it? Assuming the code to read the file works OK, that code to edit the data looks like it should work.
Re: Changing an element in an array
Got it to work. Thanks for your help!