Bonjour
je realise une application qui parcours toutes les lignes d'un richtextbox et qui supprime les espaces dans chacunes de ces lignes

Voici mon code

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
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
 
[STAThread]
static void Main() 
{
   Application.Run(new Form1());
}
 
private void od_ouvrir_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
	{
		rtb_fichier.LoadFile(od_ouvrir.FileName,RichTextBoxStreamType.PlainText); 			
		string nomfichier=od_ouvrir.FileName;		
	}
 
	private void mI_quitter_Click(object sender, System.EventArgs e)
	{
		this.Close();
	}
 
	private void mI_ouvrir_Click(object sender, System.EventArgs e)
	{
		this.od_ouvrir.ShowDialog();
	}
 
	private void bt_ouvrir_Click(object sender, System.EventArgs e)
	{
		this.od_ouvrir.ShowDialog();
	}
 
	private void sd_sauvegarder_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
	{
		rtb_fichier.SaveFile(sd_sauvegarder.FileName,RichTextBoxStreamType.PlainText); 
	}
 
	private void bt_scan_Click(object sender, System.EventArgs e)
	{
		tb_resultat.Clear();
		int I=0;
		int cpt=rtb_fichier.Lines.Length; // Nombre de lignes
		int nberreur;
		string pourcent="%";
		int position;
		nberreur=0;
 
		while (I+1<cpt)
		{		
			string lacible=rtb_fichier.Lines[I];
			int pos=lacible.Length;
			position=lacible.IndexOf(pourcent)+1;
 
				if(pos!=45)
				{
					nberreur++;
					tb_resultat.Text+="Lignes de dimension différente a la ligne "+I+" "+Environment.NewLine;
 
				}
 
 
				if(position!=0)
				{
					nberreur++;
					tb_resultat.Text+="Erreur de codification a la ligne "+I+" Caractère "+position+Environment.NewLine;
				}					
					I++;
 
		}		
 
		if(nberreur==0)
		{
 
			tb_resultat.Text="Analyse terminée avec succés";
 
		}
 
		tb_nberreur.Text="Nombre d'erreure(s) constatée(s): "+nberreur;
		tb_nberreur.ForeColor=Color.Blue;
 
	}
 
		private void bt_enregister_Click(object sender, System.EventArgs e)
		{
			sd_sauvegarder.ShowDialog();
		}
 
		private void bt_quitter_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
 
		private void bt_reparer_Click(object sender, System.EventArgs e)
		{
			int H;
			H=0;
 
			while(H<rtb_fichier.Lines.Length)
			{
				rtb_fichier.Lines[H].ToString.Trim();
				H++;
			}
 
		}
}
}
Le soucis c'est que pour la methode bt_reparer le programme se plante, je voudrais parcourir toutes les lignes une par une et effacer les espaces a chaque fois mais mon code ne fait rien du tout.

Merci d'avance
Fred

édité par neguib pour