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 Hundred Refined God Story LineThe story line of " 100 Ways to Become a God " revolved around the main character, Luo Zheng. Luo Zheng was originally a genius youth of the Luo family and the former young master of the family. After the internal strife in the family, he became a servant and a meat target for the family's disciples. He accidentally triggered the mysterious cultivation technique left behind by his father and began his journey of defying the heavens and changing his fate.
Luo Zheng's younger sister, Luo Yan, was specially recruited into the Qing-Yun Sect. She performed well in the sect, but was imprisoned in Mount Purgatory because she offended the aristocrats. In reality, she was protected and imprisoned by the sect master because her Purple Extreme Yin Body was coveted by the Central Region Overlord. Under his sister's guidance, Luo Zheng continued to reach the peak.
The story scene continued to expand, from the eastern region to the central region, then to the divine kingdom, the upper world, the divine territory, and then to the chaos, then to the divine territory, and then to the mother world. In this process, there was a confrontation between the humans, the Demon Night Race, and the demons. At the same time, there was a mysterious power hidden. The main character kept leveling up. Although the author would have more useless chapters in the process, deviate from the main line, describe unimportant characters, and drag out the plot, the main character still developed in the direction of becoming the God of Creation. He continued to grow and face various challenges through various experiences.
Four hundred words in a compositionWriting is an important art form. It can express the author's views, thoughts and feelings to the readers, so that the readers can be inspired, enlightened and enlightened. Essays could be argumentative, explanatory, prose, narrative, etc. They could also be literary works such as poems and novels.
In the process of writing, we should pay attention to the balance between thinking and expression. We should think about both the content and the form. We should express it clearly and impressively. At the same time, we should also pay attention to the mastery of writing skills and methods to improve the quality and level of writing.
You should pay attention to details and accuracy when writing. Details are an important part of a composition. Through details, the author can show the attention and detail of things and enhance the appeal and realism of the composition. The accuracy of expression is also an important issue in writing. We should follow the norms and rules of expression to make the language of the composition accurate, clear, concise and smooth.
When writing, one should also pay attention to the variety of styles. Different styles can convey different thoughts and feelings of the author.
Three or four hundred novelsHe recommended a few great novels. The author of "The Boorish Man in the Dream of the Red Chamber, Increasing His Strength in a Reckless Man." tried his best to admit his mistakes and refused to repent. He made up a historical story. The protagonist transmigrated to become Jia She's non-existent third son. After being bound to the Boor System, he was extremely reckless. He snatched the famous sword and kidnapped the princess. The ministers were afraid of him and the people loved him. Fantasy Westward Journey: A Second Journey, a game novel written by Argus. The protagonist, Dream Back 2015 Fantasy Westward Journey mobile game, had started beta testing. There was also a hard-working and rich system, and gold coins could be exchanged for money. Skeleton Sword God, a fantasy novel written by 3,000 drafts. The protagonist climbed all the way to the top. Although his grades were poor, the author's character was guaranteed to finish two novels. "Supervillain's Self-Cultivation", a fantasy novel written by Lone Bug. The protagonist transmigrated into a villain, and it was super cool to activate the villain system to kill all kinds of protagonists. "My Interstellar Industrial Empire" was a science fiction novel like an eagle spreading its wings. When Shi Lei first transmigrated into the universe, he had to systematically establish an industrial empire. The structure was huge and the characters were lively.
<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
Four-line three-gridThe four lines and three squares were mainly used for writing in Pinyin. It had four lines, and the writing of the Pinyin letters had a certain standard, such as not touching the top line of the lower grid, not stepping on the edge, and the middle grid was written on both sides of the top; The large part occupied the middle grid, and the head and hanging feet occupied two parts. The head extended upward into the middle grid, and the feet hung downward into the middle grid. The head and hanging feet occupied all the upper, middle and lower grids. For example, the single syllable, o, e, i, u, ü occupied the upper and middle grids of the four lines and three grids.
<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!
Four hundred years of film reviews400 Years was a sci-fi film directed by Stanley Kubrick that was released in 1979. The movie was a fictional story about a conflict between a modern human civilization and four ancient races. The film won many awards, including the Academy Award for Best Visual Effects. Its special effects and visual effects were considered classics in the history of movies. In addition, the music of the film was also considered one of the most outstanding in the history of film. " 400 Years of Love " was a movie that was worth watching. It not only had the unique charm of a sci-fi movie, but it also showed the variety of human history and culture.
Eight Excerptions, Four Hundred Words, Appreciation, Three Hundred WordsOnline literature referred to literary works that were spread on the Internet. Its characteristics were that it was widely spread, not limited by time and place, and not bound by traditional literature. There were many types of web novels, including fantasy, martial arts, romance, urban, science fiction, and many more. Among them, fantasy and Wuxia were the most classic types.
Fantasy novels often depicted an imaginative world with magic, martial arts, myths and other elements as the theme. All kinds of magical creatures, mysterious props, gorgeous battle scenes and so on were the highlights. The protagonists of fantasy novels were usually people with special abilities who took risks in this mysterious world to solve various problems and finally achieve their goals.
Wuxia novels, on the other hand, paid more attention to the traditional Chinese martial arts and chivalrous spirit. Their plots and characters were usually more profound and infectious. In wuxia novels, the protagonist would usually experience a series of tests and challenges to grow and eventually become a real hero.
There were many classic works in online novels such as Battle Through the Heavens, Martial Universe, and Full-time Expert. These works not only performed well in the plot and character creation, but also showed the author's deep literary foundation and creative talent.
Battle Through the Heavens was a novel with a fantasy theme. It described the story of the protagonist, Xiao Yan, who continuously grew in the process of practicing martial arts and eventually became a powerful martial artist. The novel was full of imagination and mystery. The use of various magical martial arts and magical elements made the whole story even more exciting.
Martial Yin Yang, on the other hand, was a novel with a martial arts theme. It described the story of the main character, Lin Dong, who continuously grew as he practiced martial arts, and eventually became a true martial arts expert. The description of martial arts in the novel was very detailed, and the various moves and techniques were dizzying. At the same time, it also showed the author's expression of chivalrous spirit.
The full-time expert was a novel with a gaming theme. It told the story of the protagonist, Zhang Jiale, who grew up in an esports game and eventually became a world champion. The novel was full of competitive spirit and teamwork. At the same time, it also showed the author's unique understanding and description of the game world.
" Battle Through the Heavens,"" Martial Universe,"" Master," and other works were classic examples of online novels. Not only did they perform well in the storyline and character creation, but they also demonstrated the authors 'deep literary foundation and creative talent.