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>
How do line breaks work in short stories?Line breaks in short stories often serve to create pauses, add emphasis, or transition between different thoughts or scenes. They can help control the pace and rhythm of the narrative.
2 answers
2024-10-02 06:29
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>
What kind of symbols were used to replace spaces and line breaks in computer novels?When a computer wrote a novel, it could use various symbols to replace spaces and line breaks. The following are some commonly used symbols:
- Space: Use the `` symbol to replace spaces in the text. For example,"I need 10 spaces" could be written as "I need 10 `".
- Line break: use `|'symbol to replace the line break in the text. For example,"I need 10 spaces and then write down my story" can be written as "I need 10 `"|”.
- Tabs: Use the `^` symbol to replace tabs in text. For example," I need 10 spaces to write my story " could be written as " I need 10 ``^".
These symbols can be used to replace spaces and line breaks in text, making it easier to type and edit when writing novels on a computer. However, it is important to note that different text editors or publishing software may have different explanations and usages, so it is best to check the relevant documents or tutorial before using these symbols.
17 minus 7 breaks 10Breaking Ten was a calculation method used to solve the problem of insufficient units. For the question 17 minus 7, we can first split 17 into 10 and 7, then use 10 minus 7 to get 3, and finally add 3 plus 7 to get the answer 8. Therefore, the result of 17 minus 7 was 8.
Beast Breaks the Firmament" Beast Breaks the Heavens " was a fantasy novel that mainly told the story of an orc race.
The protagonist of the story was a Beastman youth called Lin Xuan. He had a powerful self-healing ability and the power of mutated beasts. In the process of growing up, he experienced many difficulties and setbacks and made many friends. The conflict between him and the humans had led to a fierce battle. Lin Xuan continued to grow and become stronger. In the end, he defeated the evil forces and protected the peace of the Beastmen race.
The story was full of adventure, friendship, love, and other elements. The plot was full of ups and downs, and the characters were full. It was a well-received fantasy novel.
Blade Breaks the SkyBlade Breaks the Heavens was a novel co-created by Zeng Yi and He Wuhen. The story mainly told the legendary story of a good-for-nothing young master who turned the tables in another world and became a Martial God. The novel was set in the setting of a modern otaku who had transmigrated to another world. It described how he had the Sword Soul Upgrade System, obtained divine-level cultivation techniques and divine arts through killing demon beasts and cultivating, and finally became the top genius of Jade Capital. The novel was completed with a total of 2555 chapters.
The Blade Breaks The SkyBlade Breaks the Heavens was a fantasy novel written by He Wuhen. The story was about a modern otaku who transmigrated to another world and became a rich playboy in the Jade Capital. He also had the Sabersoul Upgrade System. The protagonist in the novel leveled up and became stronger by killing demon beasts and people. There was no bottleneck in his cultivation, and he could obtain divine-level cultivation techniques and divine powers. However, the given search results did not provide free full-text reading of Blade Breaks the Heavens.