L
L
libera2015-12-10 13:58:59
C++ / C#
libera, 2015-12-10 13:58:59

C# loading txt into array and division by sign?

How to do so that he would
press the button, he would download a file in which the base, in it 2 words are separated by a sign,
also in the text line by line.
Example
hello1: hello2
hello1: hello2
I need 1 hello to display in the first textbox and 2 will display word 2.
At the same time, it should delete the previous one after performing some actions.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alec Onim, 2015-12-10
@Caitiff_One

I think Split() and ReadLine() will help you.
In fact, are there any developments? The condition is not completely clear, what and who should delete and after what actions?

D
Dmitry Pavlov, 2015-12-10
@dmitry_pavlov

Something like this (I write right here - because there may be "mistakes"):

string[] lines = File.ReadLines("c:\\file.txt");
var pairs = new List<KeyValuePair>();
foreach (var line in lines) {
     string[] split = line.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
     if( split.Length != 2) continue;
     var pair = new KeyValuePair<string, string>(split[0], split[1]);
     pairs.Add(pair);
}

You will have a list of key/value pairs. You can take from it by index as from an array through the square brackets of the indexer. You can remove from the list by index using the RemoveAt method .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question