marxc88 Posted May 5, 2012 at 08:22 PM Report #453333 Posted May 5, 2012 at 08:22 PM Entao galera boa tarde e assim , eu tenho um textBOx que quando colokado um texto nele, e clikar no butao o mesmo passa para hex.. Agora o meu codigo coloka 00 a cada caracter em hex, ate ae tudo bem, o problema e que tenho que fazer com que a string sempre fique com 200 de caracters, Exemplo se a string tem 60 caracters o codigo tem que preencher com 00 ate chegar a 200... Podem me ajudar aqui o codigo que ja tenho. private void button2_Click(object sender, EventArgs e) { string idnome2 = textBox1.Text; string idnome4 = ""; foreach (char c in idnome2) idnome4 += ((UInt64)c).ToString("x4") + " "; string idnome; string character2 = "0"; idnome = "" + idnome4.Substring(2) + ""; idnome = idnome.Replace(" ", ""); int idcaracter = textBox1.Text.Length; while (idcaracter < 200) { idcaracter++; idnome = idnome + character2; } textBox3.Text = idnome; } Espero que me possao ajudar,pois no momento ele ate gera os 00 no final mas ele nao conta os caracters que preencho no textbox ae se eu colokar MARCO, no final vai ter 205 hex caracters... Podem fechar resolvi, coloquei este codigo : int valor = 101 - textBox1.Text.Length; while (idcaracter < valor) { idcaracter++; idnome = idnome + character2; }
petvetbr Posted May 5, 2012 at 08:41 PM Report #453338 Posted May 5, 2012 at 08:41 PM string idnome2 = textBox1.Text; string idnome4 = ""; foreach (char c in idnome2) idnome4 += ((UInt64)c).ToString("x4") + " "; idnome=idnome4.PadRight('0',200); //se os zeros forem à esquerda, use PadLeft ao invés de PadRight textBox3.Text = idnome; Fernando Lage Bastos - MCP/MCTS/MCPD
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now