Jump to content
Sign in to follow this  
erezlevi

erasing part of a text file

Recommended Posts

hi,

how can I erase a text file from a certain work like "don't do that" (that only exist ones within the text) till the beggining of the text file? like:

" erez went to school and the teacher said don't do that so he listen to here and return home"

I want to erase: "erez went to school and the teacher said don't do that" (including the "don't do that").

Share this post


Link to post
Share on other sites

Here's an example. Notice the commented lines.

;~ $File=FileRead("myfile.txt");You can read the file here, but I'll use the example below:

$File=" erez went to school and the teacher said don't do that so he listen to here and return home"

;Replace what you want to delete with an empty string.
$NewText=StringReplace($File,"erez went to school and the teacher said don't do that ","")

MsgBox(0,"",$NewText)

;~$FileHandle = FileOpen("myfile.txt",2);Open file in write mode. Previous content will be erased.

;~ FileWrite($FileHandle ,$NewText);Write the new content to the file.
Edited by Nahuel

Share this post


Link to post
Share on other sites

Here's an example. Notice the commented lines.

;~ $File=FileRead("myfile.txt");You can read the file here, but I'll use the example below:

$File=" erez went to school and the teacher said don't do that so he listen to here and return home"

;Replace what you want to delete with an empty string.
$NewText=StringReplace($File,"erez went to school and the teacher said don't do that ","")

MsgBox(0,"",$NewText)

;~$FileHandle = FileOpen("myfile.txt",2);Open file in write mode. Previous content will be erased.

;~ FileWrite($FileHandle ,$NewText);Write the new content to the file.

Thanks, but another problem arises:

what if the string is long and I can't put it int the replcament area?

Share this post


Link to post
Share on other sites

Well.. how big is it?

Myfile.txt:

Camels are well known for their humps. However, they do not store water in them as is commonly believed; their humps are actually a reservoir of fatty tissue. When this tissue is metabolized, it is only a source of energy, but would yield more than 1 g of water for each 1 g of fat converted through reaction with oxygen from the air. This process of fat metabolization generates a net loss of water through respiration for the oxygen required to convert the fat. [2]

Their ability to withstand long periods without water is due to a series of physiological adaptations, as described below.

They have tough feet so that they can endure the scorching desert sands.

Their red blood cells have an oval shape, unlike those of other mammals, which are circular. This is to facilitate their flow in a dehydrated state. These cells are also more stable[3] in order to withstand high osmotic variation without rupturing when drinking large amounts of water (20-25 gallons[citation needed] in one drink).

The kidneys and intestines of a camel are very efficient at retaining water. Urine comes out as a thick syrup, and their feces are so dry that they can fuel fires.

Camels are able to withstand changes in body temperature and water content that would kill most other animals. Their temperature ranges from 34 °C (93 °F) at night up to 41 °C (106 °F) during the day, and only above this threshold will they begin to sweat. The upper body temperature range is often not reached during the day in milder climatic conditions, and therefore, the camel may not sweat at all during the day. Evaporation of their sweat takes place at the skin level, not at the surface of their coat, thereby being very efficient at cooling the body compared to the amount of water lost through sweating. This ability to fluctuate body temperature and the efficiency of their sweating allows them to preserve about five litres of water a day.[citation needed]

A feature of their nostrils is that a large amount of water vapor in their exhalations is trapped and returned to their body fluids, thereby reducing the amount of water lost through respiration.

They can withstand at least 20-25% weight loss due to sweating (most mammals can only withstand about 3-4% dehydration before cardiac failure results from the thickened blood). A camel's blood remains hydrated, even though the body fluids are lost, until this 25% limit is reached.

Camels eating green herbage can ingest sufficient moisture in milder conditions to maintain their body's hydrated state without the need for drinking.

A camel's thick coat reflects sunlight. A shorn camel has to sweat 50% more to avoid overheating. It also insulates them from the intense heat that radiates from hot desert sand. Their long legs help by keeping them further from the hot ground. Camels have been known to swim.

Their mouth is very sturdy, able to chew thorny desert plants. Long eyelashes and ear hairs, together with sealable nostrils, form an effective barrier against sand. Their gait (moving both legs on one side at the same time) and their widened feet help them move without sinking into the sand.

All camelids have an unusual immune system. In other species, the Y-shaped antibody molecules consist of two heavy (or long) chains along the length of the Y, and two light (or short) chains at the tips of the Y. In the camel, the antibody molecules have only two heavy chains, which makes them smaller and more durable. These antibodies, which were discovered in 1993, probably developed 50 million years ago, after camelids split fronm ruminants and pigs, according to biochemist Serge Muyldermans.[4]

The camel is the only animal to have replaced the wheel (mainly in North Africa) where the wheel had already been established. The camel was not removed from the top of the transport industry in these areas until the wheel was combined with the internal combustion engine in the 20th century.

delete.txt:

They can withstand at least 20-25% weight loss due to sweating (most mammals can only withstand about 3-4% dehydration before cardiac failure results from the thickened blood). A camel's blood remains hydrated, even though the body fluids are lost, until this 25% limit is reached.

Camels eating green herbage can ingest sufficient moisture in milder conditions to maintain their body's hydrated state without the need for drinking.

A camel's thick coat reflects sunlight. A shorn camel has to sweat 50% more to avoid overheating. It also insulates them from the intense heat that radiates from hot desert sand. Their long legs help by keeping them further from the hot ground. Camels have been known to swim.

code:

$File=FileRead("myfile.txt")
$PartToDelete=FileRead("delete.txt")
;Replace what you want to delete with an empty string.
$NewText=StringReplace($File,$PartToDelete,"")

$FileHandle = FileOpen("myfile.txt",2);Open file in write mode. Previous content will be erased.

FileWrite($FileHandle ,$NewText);Write the new content to the file.

Share this post


Link to post
Share on other sites

Well.. how big is it?

Myfile.txt:

Camels are well known for their humps. However, they do not store water in them as is commonly believed; their humps are actually a reservoir of fatty tissue. When this tissue is metabolized, it is only a source of energy, but would yield more than 1 g of water for each 1 g of fat converted through reaction with oxygen from the air. This process of fat metabolization generates a net loss of water through respiration for the oxygen required to convert the fat. [2]

Their ability to withstand long periods without water is due to a series of physiological adaptations, as described below.

They have tough feet so that they can endure the scorching desert sands.

Their red blood cells have an oval shape, unlike those of other mammals, which are circular. This is to facilitate their flow in a dehydrated state. These cells are also more stable[3] in order to withstand high osmotic variation without rupturing when drinking large amounts of water (20-25 gallons[citation needed] in one drink).

The kidneys and intestines of a camel are very efficient at retaining water. Urine comes out as a thick syrup, and their feces are so dry that they can fuel fires.

Camels are able to withstand changes in body temperature and water content that would kill most other animals. Their temperature ranges from 34 °C (93 °F) at night up to 41 °C (106 °F) during the day, and only above this threshold will they begin to sweat. The upper body temperature range is often not reached during the day in milder climatic conditions, and therefore, the camel may not sweat at all during the day. Evaporation of their sweat takes place at the skin level, not at the surface of their coat, thereby being very efficient at cooling the body compared to the amount of water lost through sweating. This ability to fluctuate body temperature and the efficiency of their sweating allows them to preserve about five litres of water a day.[citation needed]

A feature of their nostrils is that a large amount of water vapor in their exhalations is trapped and returned to their body fluids, thereby reducing the amount of water lost through respiration.

They can withstand at least 20-25% weight loss due to sweating (most mammals can only withstand about 3-4% dehydration before cardiac failure results from the thickened blood). A camel's blood remains hydrated, even though the body fluids are lost, until this 25% limit is reached.

Camels eating green herbage can ingest sufficient moisture in milder conditions to maintain their body's hydrated state without the need for drinking.

A camel's thick coat reflects sunlight. A shorn camel has to sweat 50% more to avoid overheating. It also insulates them from the intense heat that radiates from hot desert sand. Their long legs help by keeping them further from the hot ground. Camels have been known to swim.

Their mouth is very sturdy, able to chew thorny desert plants. Long eyelashes and ear hairs, together with sealable nostrils, form an effective barrier against sand. Their gait (moving both legs on one side at the same time) and their widened feet help them move without sinking into the sand.

All camelids have an unusual immune system. In other species, the Y-shaped antibody molecules consist of two heavy (or long) chains along the length of the Y, and two light (or short) chains at the tips of the Y. In the camel, the antibody molecules have only two heavy chains, which makes them smaller and more durable. These antibodies, which were discovered in 1993, probably developed 50 million years ago, after camelids split fronm ruminants and pigs, according to biochemist Serge Muyldermans.[4]

The camel is the only animal to have replaced the wheel (mainly in North Africa) where the wheel had already been established. The camel was not removed from the top of the transport industry in these areas until the wheel was combined with the internal combustion engine in the 20th century.

delete.txt:

They can withstand at least 20-25% weight loss due to sweating (most mammals can only withstand about 3-4% dehydration before cardiac failure results from the thickened blood). A camel's blood remains hydrated, even though the body fluids are lost, until this 25% limit is reached.

Camels eating green herbage can ingest sufficient moisture in milder conditions to maintain their body's hydrated state without the need for drinking.

A camel's thick coat reflects sunlight. A shorn camel has to sweat 50% more to avoid overheating. It also insulates them from the intense heat that radiates from hot desert sand. Their long legs help by keeping them further from the hot ground. Camels have been known to swim.

code:

$File=FileRead("myfile.txt")
$PartToDelete=FileRead("delete.txt")
;Replace what you want to delete with an empty string.
$NewText=StringReplace($File,$PartToDelete,"")

$FileHandle = FileOpen("myfile.txt",2);Open file in write mode. Previous content will be erased.

FileWrite($FileHandle ,$NewText);Write the new content to the file.

well that is great and very helpful. another question: what if the text within the files changes? but only the Topics don't.

how can i seperate the Topics and their text from each other?

Share this post


Link to post
Share on other sites

well that is great and very helpful. another question: what if the text within the files changes? but only the Topics don't.

how can i seperate the Topics and their text from each other?

Sorry, I don't understand... Topics?

Share this post


Link to post
Share on other sites

Sorry, I don't understand... Topics?

first thanks for your help.

here is an example text: (topic = start of the text allways the same in two parts of the file)

exapmle:

"topic: Stock market:"

bla bla bla bla bla bla bla bla bla } text changes and don't stay the same.

"topic: Car rental"

bla bla bla bla bla bla bla bla bla } text changes and don't stay the same.

I need both topics either in two seperate files, or only the second topic to an integer like: $car.

any idea?

Share this post


Link to post
Share on other sites

I guess that depends on the exact format it is. if the file is like this, for example:

"topic:Stock market:"
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah 
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah 
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah

then this should work:

#include <String.au3>

$File='"topic: Stock market:"' & @CR & _
       "bla bla bla bla bla bla bla bla bla"

$Topic=_StringBetween($File,'topic:',':')

MsgBox(0,"",$Topic[0])

If your files have a different format, take a look at the String*() functions.

StringSplit()

_StringBetween()

StringRegExp()

etc.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...