Download . txt to memory and read

Asked

Viewed 328 times

0

How to download TXT in memory, read and save in a variable separated by , the words? I wanted to read with the slip (I think it’s the name, I don’t remember...).

Here it is, it downloads the file to RAM:

public static bool CheckUpdate()
        {
            System.Net.WebClient wb = new System.Net.WebClient(); //Classe usada para baixar o arquivo de info
            byte[] buffer = wb.DownloadData(remoteVersionFile); //Baixa o arquivo de info para a memória
            System.IO.MemoryStream mem = new System.IO.MemoryStream(buffer); //Cria um Stream para o buffer
            System.IO.StreamReader memReader = new System.IO.StreamReader(mem); //Cria um leitor para o Stream
            Version remoteVersion = new Version(memReader.ReadToEnd()); // Lê a versão do arquivo para uma variável do tipo Versio;
            memReader.Close();
            mem.Close();

            Version localVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; // Retorna a versão do Assembly (Programa) em execução
            return remoteVersion > localVersion; //Retorna true se a versão na internet for maior que a versão do aplicativo em execução;
        }`

Here is my variable, which I keep in txt and read in txt when it is in ram:

"NoiseFix.cs",
"HPArmorDigital.cs",
"Nomes das ruas.cs",
"Neon.cs",
"Indicador cansaço.cs",
"Sensitivity.cs",
"Strobs.cs",
"Memoryfix.cs",
"MFGTAVH.cs",
"Fogo no escapamento.cs",
"PontosCardeais.cs",
"Xenon.cs",
"MarcasDeTiro.cs",
"Zoom.cs",
"PerPixelLighting.cs",
"Sun.cs",
"Sunlight.cs",
"RainModEffect.cs",
"SnowFlakes.cs",
"Recarregararma.cs",
"Exhaust.cs",
"Skybox.cs",
"Fontfixed.cs",
"camshake.cs",
"turn_indicators.cs",
"particles.cs",
"Skyboxv2.cs",
  • You seek the Split()?

  • Yes I want to download the TXT to the ram and read it and save in a variable and it would be with Split to read, the function to download the ram I have now need only read the TXT saved in the ram....

  • 1

    Why don’t you read and write Txt with File.Readalllines() File.Writealllines()? Much simpler

1 answer

0

If I understand correctly you want to know how to write and read a txt, it is time to read separate by ",". I will leave an example here, see if it suits you.

Escrever Txt:

IList<string> lista = new List<string>() { "teste", "teste2", "teste3"};

File.WriteAllLines("caminho_arquivo.txt", lista);

Where, the file path is the file that will be created, and the list is a collection of strings (List or Array), where each element of it will be a txt line.

Ler Txt:

string[] lista = File.ReadAllLines("caminho_arquivo.txt");

foreach(string linha in lista)
{
     //Codigo para cada item da lista de linhas do arquivo
}

Where File.Readalllines returns an Array of strings, being formed by each line of the file.

Example of Split();

string nomes = "Joao, Paulo, Sergio, Rodrigo, Pedro";

string[] lista = nomes.Split(',');

Where, the split breaks your string into the character you entered, returning a string array.

  • And if there’s a comma in the name in there?

  • The text will be broken, and if there is a possibility of comma in the name, it will have to be treated differently. But in the question it was described that he wanted to separate by comma anyway, so it probably won’t happen.

  • He mentioned filenames that might have comma, and if you have break everything, without error

  • Could be, I misinterpreted the question then.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.