Answer the question
In order to leave comments, you need to log in
How to remove all text that contains 32 characters?
There is a file with a lot of data, you need to make sure that all the text in which 32 characters is deleted, for example, if the file contains text containing 32 characters, then it should be deleted, that is, the text 12345678901234567890123456789012 should be deleted after the script is run (Like all text containing 32 characters), the rest of the text containing more or less characters must be kept12345678901234567890123456789012
Answer the question
In order to leave comments, you need to log in
1. We create bufio.Reader, for this we call bufio.NewReader(...), passing the open file there. https://golang.org/pkg/bufio
2. By calling ReadString('\n') on the created reader, we read the file line by line.
3. We beat each line into words using strings.Split(...., " ")
4. We get an array of words, run through it in a loop and look at the lengths of the words.
5. We write to the file we need only those words that are shorter than 32 characters.
It is important that if your file contains not only ASCII characters, then to calculate the length you need not just look at the number of bytes, but use the function https://golang.org/pkg/unicode/utf8/#RuneCountInString
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question