Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7765561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:11:47+00:00 2026-06-01T15:11:47+00:00

So here is my problem, I’m trying to get the content of a text

  • 0

So here is my problem, I’m trying to get the content of a text file as a string, then parse it. What I want is a tab containing each word and only words (no blank, no backspace, no \n …) What I’m doing is using a function LireFichier that send me back the string containing the text from the file (works fine because it’s displayed correctly) but when I try to parse it fails and start doing random concatenation on my string and I don’t get why.
Here is the content of the text file I’m using :

truc,
ohoh,
toto, tata, titi, tutu,
tete,

and here’s my final string :

;tete;;titi;;tata;;titi;;tutu;

which should be:

truc;ohoh;toto;tata;titi;tutu;tete;

Here is the code I wrote (all using are ok):

namespace ConsoleApplication1{

class Program
{
    static void Main(string[] args)
    {
        string chemin = "MYPATH";
        string res = LireFichier(chemin);
        Console.WriteLine("End of reading...");
        Console.WriteLine("{0}",res);// The result at this point is good
        Console.WriteLine("...starting parsing");
        res = parseString(res);
        Console.WriteLine("Chaine finale : {0}", res);//The result here is awfull
        Console.ReadLine();//pause
    }

    public static string LireFichier(string FilePath) //Read the file, send back a string with the text
    {
        StreamReader streamReader = new StreamReader(FilePath);
        string text = streamReader.ReadToEnd();
        streamReader.Close();
        return text;
    }

    public static string parseString(string phrase)//is suppsoed to parse the string
    {
        string fin="\n";
        char[] delimiterChars = { ' ','\n',',','\0'};
        string[] words = phrase.Split(delimiterChars);

        TabToString(words);//I check the content of my tab

        for(int i=0;i<words.Length;i++)
        {
            if (words[i] != null)
            {
                fin += words[i] +";";
                Console.WriteLine(fin);//help for debug
            }
        }
        return fin;
    }

    public static void TabToString(string[] montab)//display the content of my tab
    {
        foreach(string s in montab)
        {
            Console.WriteLine(s);
        }
    }
}//Fin de la class Program
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:11:48+00:00Added an answer on June 1, 2026 at 3:11 pm

    Try this:

    class Program
        {
            static void Main(string[] args)
            {
                var inString = LireFichier(@"C:\temp\file.txt");
                Console.WriteLine(ParseString(inString));
                Console.ReadKey();
            }
    
            public static string LireFichier(string FilePath) //Read the file, send back a string with the text
            {
                using (StreamReader streamReader = new StreamReader(FilePath))
                {
                    string text = streamReader.ReadToEnd();
                    streamReader.Close();
                    return text;
                }
            }
    
            public static string ParseString(string input)
            {
                input = input.Replace(Environment.NewLine,string.Empty);
                input = input.Replace(" ", string.Empty);
                string[] chunks = input.Split(',');
                StringBuilder sb = new StringBuilder();
                foreach (string s in chunks)
                {
                    sb.Append(s);
                    sb.Append(";");
                }
                return sb.ToString(0, sb.ToString().Length - 1);
            }
        }
    

    Or this:

    public static string ParseFile(string FilePath)
    {
        using (var streamReader = new StreamReader(FilePath))
        {
            return streamReader.ReadToEnd().Replace(Environment.NewLine, string.Empty).Replace(" ", string.Empty).Replace(',', ';');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Unusual problem here: I have an app that uses a text file which contains
date here my problem: String datetime = 2012-03-24 23:20:51; I know that that string
I have a problem here with this code. I'm opening a socket, then listening
Got a problem here on exiting onclick. The program uses shared preferences to get
here my problem, i'm using asp.net for my site, i get a list of
Here is problem I'm trying to solve. It's for logistics company. I got all
Odd problem here. Working with an existing system that uses TinyMCE as it's text
I am having problem here with bitmaps..I want to remove the black background that
Weird problem here, I'm trying to use a global function to update my settings
Small problem here. I have an event created on Facebook and am using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.