0
In my notepad has 2620 lines which is the maximum.
>PRODUTO [1]
1. Exemplo de texto 1
2. Exemplo de texto 2
>PRODUTO [2]
1. Exemplo de texto 1
2. Exemplo de texto 22
>PRODUTO [3]
1. Exemplo de texto 1
2. Exemplo de texto 2
3. Exemplo de texto 3
@lazyFox: How are you reading the file?
public void Ler_TXT()
{
string linha = string.Empty;
List<List<String>> texto = new List<List<String>>();
StreamReader arquivo = new StreamReader($@"C:\Minha Pasta\MeuTexto.txt", Encoding.UTF8);
while ((linha = arquivo.ReadLine()) != null)
{
if (linha.StartsWith($">PRODUTO"))
{
texto.Add(new List<String>());
}
else
{
texto.Last().Add(linha);
}
}
}
It is possible to change a specific text without rewriting the whole text?
You can see on the line : 2. Exemplo de texto 22
is number "2" longer. How can I change specific text. I have the value "PRODUTO [2]"
and have value "2."
, how can I do this in C# ?
How are you reading the file?
– lazyFox
@lazyFox wait, I will edit question.
– Matheus Miranda
By the way this file was generated by code put also the "writing"
– lazyFox
This seems to me very punctual, maybe it would be better to do in Notepad++ with a macro for example. And anyway, I’d have to rewrite the whole file again, just the fact of reading and saving the file would already be rewriting it
– Rovann Linhalis
@lazyFox i no file by logic, is a txt downloaded on the internet (It’s ready).
– Matheus Miranda
@Rovannlinhalis 2620 lines is not much for rewriting the whole text?
– Matheus Miranda
@lazyFox edited question.
– Matheus Miranda
Yes you will have to rewrite the whole file anyway, but with 2620 lines it is a relatively small file.
– lazyFox
@lazyFox all right, because this file is bigger than I have, the rest are less than 2620 lines.
– Matheus Miranda
Let me see if I understand, you want to read the file and remove all the repeated digits within one
>Produto [n]
?– Leandro Angelo
@Leandroangelo No, update only one line, because I already have value
PRODUTO [2]
and2.
stored in memory. Because sometimes comes a wrong word, then I want to correct.– Matheus Miranda
@Matheusmiranda How do you want to find the line? By content, content, regex or other option?
– Jéf Bueno
@LINQ for content is enough.
– Matheus Miranda
@Matheusmiranda Why do you read the file that way? I guess I don’t quite understand what you’re doing... You have the file ready and want to make this fix, right?
– Jéf Bueno
@LINQ here is the answer because I read the file: https://answall.com/a/245852/54019 and Yes I want to do this correction just one line.
– Matheus Miranda