Read the spaces and line breaks in the txt fileIn Python, when you use the built-in function open() to open a txt-file, it will return the contents of the file as a string by default. At this time, the spaces and newlines in the txt-file will be retained correctly. For example, if there was a file named text.txt:
Hello
world!
How are you?
Read it using the following code:
```python
with open("text.txt", "r") as f:
content = f.read()
```
At this point, the spaces and line breaks in the original text in the string contained in the content variable are preserved.
If you want to deal with spaces and line breaks, there are two situations:
- ** Remove spaces and line breaks **: You can use the replace() method for strings. This method accepts two parameters. The substring to be replaced is the first argument, and the string to be replaced is the second argument. For operations that remove spaces and line breaks, replace them with an empty string. For example:
```python
with open("text.txt", "r") as f:
content = f.read().replace(" ", "").replace("\n", "")
print(content)
```
The output was: Hello world! Howareyou?。
- ** Preserve spaces and line breaks **: Similarly, use the replace() method of strings and pass the empty string as the second argument to the replace() method. For example:
```python
with open("text.txt", "r") as f:
content = f.read().replace("\n", "<br>").replace(" ", " ")
print(content)
```
The output is: Hello<br> world! <br><br>How are you?,This is to replace the line break with an browser tag.<br>, spaces were replaced with the original format.
In addition, you can also read the txt-file and process the spaces and line breaks in it in javelin, for example:
```javascript
function load(name) {
let xhr = new XMLHttpRequest(),
okStatus = document.location.protocol === "file:"? 0 : 200;
xhr.open('GET', name, false);
xhr.overrideMimeType("text/ml;charset= utf-8");//default is utf - 8
xhr.send(null);
return xhr.status === okStatus? xhr.responseText : null;
}
function write(str) {
var newStr = str.replace(/\s+/g, '\n');
console.log(newStr);
document.getElementById("text").innerHTML = newStr;
}
var text = load("test.txt");
write(text);
```
In the above code, you use the XMTPRequest object to read the contents of the txt-file, and then use the replace() method to replace multiple consecutive white space characters (including spaces, tabs, newlines, etc.) with a single newline.
<a href="/?from=ask_words" style="color:red" target="_blank">Read more exciting novels for free</a>
A novel that breaks through my mother's bottom lineI recommend " It's Not Easy to Be a Mother in the Future." This is a super interesting sci-fi space novel. The female protagonist transmigrated into the stallion novel and became the mother of the male protagonist's younger brother who died early. The son's cheap father was the cannon fodder big BOSS. The male protagonist had a bad character and his wife was difficult to deal with, so the female protagonist wanted to stay away from them. Even though the author's updates were extremely slow and he always stopped updating, he had recently started updating again. The female lead didn't have a big cheat, and she even snatched the male lead's cheat for the villain BOSS to use. The little bun in the book was very cute. The interaction between the family was especially loving. There was a contrast between cuteness and warm affection. The overall style was relaxed and pleasant. Although it might be a big trap, the content was really good and worth reading.
Also, I'm Bao Ma at the End of the World was great. This was a post-apocalyptic crisis novel written by Bao Bao Zi. It was about the story of Bao's mother taking care of her child and struggling to survive in the post-apocalyptic world. The female protagonist was a human-shaped computer that was constantly upgrading, and the male protagonist was the commander of the Xiang City garrison that was a slave to his daughter. In the plot, there was panic and changes in human nature when the apocalypse came. The male and female leads worked together to build a stable home. The author's update was awesome, and the quality of the novel was guaranteed. The mother and baby in the book were both touching and funny. It was a very loving post-apocalyptic novel.
In addition, I recommend " Bring Mom to Cultivate Immortal ". After the female protagonist's fate was bad, she was reborn with her mother and even obtained an immortal mansion and many treasures. After that, she started her journey of cultivation. The female protagonist's family was full of the aura of a Virgin Mary. It was a relatively special novel in the Xianxia novels.
The Top 10 Best Mothers to Wear Quickly was also worth recommending. This was a story about raising children. The female protagonist became their mother to protect the children. The story involved all kinds of family problems. It was very realistic. Some of the plots were uncomfortable, but there were also very touching parts, like the little girl becoming a ghost mother who accompanied her. The idea was about family education, and it could make people think deeply.
The novel," The Couple's Universe: The Amazing Legend of Shen Zhen " is equally exciting. Everyone is welcome to click and read it!
A novel where the instructor breaks through the rookie's psychological defense lineI recommend Long Live Coach. This was a sports novel written by Overwhelming the Difficulties. The main character was a super good coach who could solve any problem, including running too fast and jumping too low. Different from his previous book, The All-round Athlete, this book was written about a coach. The technical details, structure, and plot were all good, and the rhythm was smooth. Although the system's ability was a little out of place like a stimulant, and the emotional scenes were awkward, it was a good book overall. It was suitable for sports enthusiasts and bookworms. The author had a strong creative ability. The book had a novel theme and was well written. It was quite worth reading.
I would recommend 'It's Hard to Be an Elf Undercover'. It was a light novel by Pharaoh and the Sand Sculpture. The protagonist, Amamiya, traveled to the Pokémon world and had the ability to see through things. Then, she went undercover in various villains 'organizations, like a mission impossible. The male supporting character, Yu Longdu, was also a spy. This book was hilarious. The description of the bond between elves and humans was on point. There were no dark or strange settings in the city. The world view was very simple, and the plot was catchy. The combat elements were also good. Although the ending was a little bad, it was overall good. When reading it, one could not help but laugh.
<a href="/?from=ask_words" style="color:red" target="_blank">Read more exciting novels for free</a>
the story is decent but the writing is awful. he massively overuses commas and line breaks and makes the entire book seem extremely stilted