System.IndexOutOfRangeException was unhandled
Bonjour .
ou est le problème dans le code suivant?
toujours affiche un exception
Citation:
System.IndexOutOfRangeException was unhandled ; Message=Index was outside the bounds of the array.
dans la ligne :
Code:
Console.WriteLine(TStopWords[2]);
est la valeur de k est toujour 1,
Code:
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static string[] decoupage(string chaine)
{
Regex myRegex = new Regex(@"\d+");
return myRegex.Split(chaine);
}
static void Main(string[] args)
{
int i = 1;
//; i
// {
string a = @"E:\Cat_De_Textes\stopswords.txt";
StreamReader Sr = File.OpenText(a);
string[] TStopWords = decoupage(Sr.ReadToEnd());
Console.WriteLine(TStopWords[2]);
int k;
for (k=0 ;k< TStopWords.ToArray().Count(); k++)
{ Console.WriteLine(Sr.ToString()[k]); }
Console.WriteLine(k);
string nomfichier = "T" + i.ToString();
String Path = @"E:\Cat_De_Textes\Corpus\" + nomfichier + ".txt";
StreamReader sr = new StreamReader(Path);
string SGlob = sr.ReadToEnd();
sr.Close();
//remplacer les StopWords Par ""
// for (int j = 0; j < SGlob.Length; j++)
// {
bool fond = false;
string[] SGlobDec = decoupage(SGlob);
Console.WriteLine(SGlobDec.Length);
Console.ReadKey();
foreach (string str in SGlobDec)
{
for (int h = 0; h < TStopWords.Length; h++) if (str == TStopWords[k]) fond = true;
if (fond == true) SGlob = SGlob.Replace(str, " ");
fond = false;
}
// }
// }
}
}
} |