1. I Need to search in a file by reading it character by character, the problem is that each line ends with spaces before the next line begins......... how to remove spaces between lines and make the search contiue automatically.


2. In another case I need to read a file line by line and process it. to ger a new file where each line contains no more that 30 characters and the rest of characters make a new line and so on........... .

how are you currently reading the file

am reading line of the first line as string, using strlen() calculate the size then divide string into parts (parse string)......... write to the text file again.... still working on it .

for removing spaces from the end of files, I dont know how to do it ........ I have one idea I am working on......... read character by character if its not space write to anew file if its space read the next character..................still working on it

Use this code to read the lines it will automatically read the lines in the file

string filename="D:\folder\file.txt";
  using (StreamReader reader = new StreamReader(@filename))
    {      
        while ((S = reader.ReadLine()) != null)
        {
          //YOUR CODE           
                
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.