Bonjour,
j'essaye de créer une fonction qui va couper une chaine string et me la renvoyer en tableau de string
Donc par exemple je lui envoi 111222333 et elle retourne 111, 222, 333 et j'affiche le contenu dans un richTextBox.
Le problème c'est que ma fonction "SplitString" me renvoi System.Char[]...
Je ne comprend pas trop...
Voici le code C# :
J'ai besoin de cette fonction (tel quel) pour un autre programme en cours de développement...
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 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string input = "aaaaaabbbbbbccccccdddddddeeeeeeeffffffgggggg"; string[] arr = SplitString(input, 6); StringBuilder sortie = new StringBuilder(); for (int i = 0; i <= arr.Length - 1; i++) { if (i == arr.Length - 1) { sortie.Append("\"" + arr[i].ToString() + "\""); } else { sortie.Append("\"" + arr[i].ToString() + "\"" + " + _" + System.Environment.NewLine); } } richTextBox1.Text = sortie.ToString(); } private static string[] SplitString(string input, int partsize) { decimal valeur = input.Length / partsize; int amount = (int)(Math.Ceiling(valeur)); string[] oout = new string[amount]; int currentpos = 0; for (int I = 0; I <= amount - 1; I++) { if (I == amount - 1) { char[] temp = new char[(input.Length - currentpos)]; input.CopyTo(currentpos, temp, 0, (input.Length - currentpos)); oout[I] = temp.ToString(); } else { char[] temp = new char[partsize]; input.CopyTo(currentpos, temp, 0, partsize); oout[I] = temp.ToString(); currentpos += partsize; } } return oout; } } }
Merci d'avance pour votre aide^^
Partager