L'analyse de la chaîne de C#

Donc voici mon problème, je suis en train de récupérer le contenu d'un fichier texte en tant que chaîne de caractères, puis de l'analyser. Ce que je veux, c'est un onglet contenant chaque mot et des mots seulement (pas de vide, pas de retour, pas de \n ...) Ce que je fais est d'utiliser une fonction LireFichier que me renvoyer la chaîne de caractères contenant le texte à partir du fichier (fonctionne très bien parce qu'il s'affiche correctement) mais quand j'essaie de l'analyser échoue et commencer à faire des enchaînement aléatoire sur ma chaîne et je ne comprends pas pourquoi.
Voici le contenu du fichier texte que j'utilise :

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

et voici ma chaîne finale :

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

qui devrait être:

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

Voici le code que j'ai écrit (en utilisant tous sont 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',',','
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
}
'
}; 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 }
var newstr = String.Join(";", Regex.Matches De Fichier.ReadAllText(@"c:\temp\aa.txt"), @"[\w\d]+" ) .Cast<le Match>() .Sélectionnez(m=>m.Valeur));

OriginalL'auteur WizLiz | 2012-04-11