// Je voudrais faire un truc comme ca this.textBox1.Text = stMaStructure.bMonTableauDebytes.ToString(); // J'ai essayé ça: this.textBox4.Text = stMaStructure.bMonTableauDebytes.UnsafeAsciiBytesToString(3); this.textBox4.Text = Convert.ToString(stMaStructure.bMonTableauDebytes, 16); this.textBox4.Text = System.Text.Encoding.ASCII.GetString(&stMaStructure.bMonTableauDebytes[0], 0, 7); // Mais rien ne fonctionne
byte[] array = new byte[10] { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x50}; // on considere que le tableu de byte contient de l'ASCII pur string str = new string( UnicodeEncoding.ASCII.GetChars(array));
unsafe public struct ST_MA_STRUCTURE { ... public short sShort1; public short sShort2; public fixed byte bMonTableauDebytes1[7]; public fixed byte bMonTableauDebytes2[14]; public float fFloat1; ... } public ST_MA_STRUCTURE stMaStructure = new ST_MA_STRUCTURE();
this.textBox4.Text = new string(UnicodeEncoding.ASCII.GetChars(&stMaStructure .bMonTableauDebytes1[0]));
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionthis.textBox4.Text = new string(UnicodeEncoding.ASCII.GetChars(stMaStructure.bMonTableauDebytes1));
this.textBox4.Text = new string(UnicodeEncoding.ASCII.GetChars(stMaStructure.bMonTableauDebytes1));
[StructLayout(LayoutKind.Explicit, Size =364,CharSet = CharSet.Ansi)] unsafe public class ST_MA_STRUCTURE { ... [FieldOffset(10)] public short sShort1; [FieldOffset(12)] public short sShort2; [FieldOffset(14)] public fixed byte bMonTableauDebytes1[7]; [FieldOffset(21)] public fixed byte bMonTableauDebytes2[14]; [FieldOffset(35)] public float fFloat1; ... }
unsafe { fixed (ST_MA_STRUCTURE* p = &stMaStructure) // on défini un pointeur de travail { byte[] tab=new byte[7]; // un tableau C# classique for ( int i = 0; i< 7; i++) // on copy du tableau fixé vers le classique tab[i] =p->bMonTableauDebytes1[i]; //Là on devrait pouvoir utiliser les fonctions du code natif, attention il faut enlever les \0 en fin de chaines string Text = new string(UnicodeEncoding.ASCII.GetChars(tab)).Trim('\0'); } }