Bonjours,
J'ai un peu de difficultés au niveau d'une méthode..

Je dois découper un string (fichier texte dans une string) en mot. Cependant, je ne dois pas avoir de duplicata, ni de ponctuation et ni d'espace. Un genre de dictionnaire quoi.

Pour ce qui est des duplicatas, j'ai une superbe méthode qui fonctionne à merveille.

Voici ma méthode pour le reste.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 public void TransferMots(string texte)
        {
            int g = 1;
            int f = 0;
            char[] tabIndex = texte.ToCharArray();
            for (int i = 1; i < (tabIndex.Length-1); i++)//crée le tableau d'index pour la séparation des mots
            {
 
                if (char.IsWhiteSpace(tabIndex[i])&( (char.IsLetter(tabIndex[i - 1]) & char.IsLetter(tabIndex[i + 1]))))
                {
                    tabMot[f] = i;
                    f++;
                    tabMot[f] = i;
                    f++;
                }
                else if (char.IsWhiteSpace(tabIndex[i]) & (char.IsLetter(tabIndex[i - 1]) | char.IsLetter(tabIndex[i + 1])))//Reste a déterminer 
                {
                    tabMot[f] = i;
                    f++;
                    tabMot[f] = i;
                    f++;
                }
            }
            for (int i = 0; i < 379; i++)//transpher les mots du string normaliser dans la liste......revoir les indexs,le 200 est temporaire
            {
                if (texte[i] == ' ')
                {
                    dictio.Add(texte.Substring(tabMot[g], (tabMot[g + 1] - tabMot[g])));
                    g++;
                    g++;
                }
            }
        }

Elle contient beaucoup de faille. Je ne vois pas comment je pourrais l'optimisé et la faire fonctionner a 100%.
Merci de votre aide!