<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8373220483460808467</id><updated>2011-11-27T17:11:17.286-08:00</updated><title type='text'>Converting from Char to String on Visual C++ 2005</title><subtitle type='html'>This blog explains the process to convert from Char to String and String to Char on Visual C++ 2005.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://chartostringusingvisualcmasmas2005.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8373220483460808467/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://chartostringusingvisualcmasmas2005.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jaime Montoya</name><uri>http://www.blogger.com/profile/16823894261113468942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://3.bp.blogspot.com/_xxqD9isjXyY/S6xjpG1cqfI/AAAAAAAAO18/D6l_ssNuNNA/S220/jaimemontoya.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8373220483460808467.post-4095505783232518874</id><published>2007-04-30T08:58:00.000-07:00</published><updated>2007-11-04T09:29:44.099-08:00</updated><title type='text'>Converting from Char to String on Visual C++ 2005</title><content type='html'>&lt;div style="text-align: justify;"&gt;If working on a Windows Form application, under the name spaces we declare: char juan[20];. It should look like this:&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using namespace&lt;/span&gt; System;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using namespace&lt;/span&gt; System::ComponentModel;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using namespace&lt;/span&gt; System::Collections;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using namespace&lt;/span&gt; System::Windows::Forms;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using namespace&lt;/span&gt; System::Data;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using namespace&lt;/span&gt; System::Drawing;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;char&lt;/span&gt; juan[20];&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Code for button1&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;textbox1-&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;private&lt;/span&gt;: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;//This For is to fill with blank spaces all of the values in the Char arrays so that they don't save values from former processes. &lt;/span&gt;&lt;br /&gt;             &lt;span style="color: rgb(51, 51, 255);"&gt;for&lt;/span&gt;(&lt;span style="color: rgb(51, 51, 255);"&gt;int&lt;/span&gt; i=0;i&amp;lt;50;i++){&lt;br /&gt;                 juan[i]=' ';&lt;br /&gt;            }&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;                 &lt;span style="color: rgb(51, 51, 255);"&gt;               for&lt;/span&gt; (&lt;span style="color: rgb(51, 51, 255);"&gt;int&lt;/span&gt; i = 0 ; i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/textbox1-&gt;&amp;lt;&lt;textbox1-&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;textBox1-&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/textbox1-&gt;&amp;gt;&lt;textbox1-&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Text-&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/textbox1-&gt;&amp;gt;&lt;textbox1-&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Length ;i++)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;                    juan[i] =  textBox1-&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/textbox1-&gt;&amp;gt;&lt;textbox1-&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Text[i];            &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;                }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;text-&gt;&lt;br /&gt;&lt;br /&gt;&lt;/text-&gt;&lt;/textbox1-&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Code for button2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt; &lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;private&lt;/span&gt;: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {&lt;br /&gt;     textBox2-&amp;gt;Text="";&lt;br /&gt;     &lt;span style="color: rgb(51, 51, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(51, 51, 255);"&gt;int &lt;/span&gt;i = 0 ; i&amp;lt; 20; i++)&lt;br /&gt;         textBox2-&amp;gt;Text += Char::ToString(juan[i]); &lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;&lt;text&gt;&lt;/text&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;The user of the program is going to write something on textBox1. But all what the user writes on textBox1 is by default considered and taken as String type. But we want to convert all what is oin textBox1 from its default String type to Char type. So first of all we declare an array with Char type, like this:&lt;br /&gt;&lt;br /&gt;char juan[20];&lt;br /&gt;&lt;br /&gt;Now we are ready to write code for the button1, and its work will be to transform the String information introduced by the user from button1, to Char type.&lt;br /&gt;&lt;br /&gt;Once the information has been converted from String to Char, we already have data on our Char array, but we can't see it because it is just in memory. If we want to see in a textBox what is in our Char array, we must convert what is in the array, from Char to String, why?, well because a textBox would be capable to print out easily a String type, but never a Char type. To print out directly a Char element into a textBox is just impossible. So the button2 of our program would be the responsible to perform such conversion from Char to String and finally we will see on textBox2 what is saved in our Char array.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Spanish version/Versión en español&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;Si se está trabajando en una Aplicación de Windows Forms, bajo los nombres de espacio declaramos: char juan[20];.  Debería verse así:&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using namespace&lt;/span&gt; System;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using namespace&lt;/span&gt; System::ComponentModel;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using namespace&lt;/span&gt; System::Collections;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using namespace&lt;/span&gt; System::Windows::Forms;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using namespace&lt;/span&gt; System::Data;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;using namespace&lt;/span&gt; System::Drawing;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;char&lt;/span&gt; juan[20];&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Código para el button1&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;textbox1-&gt;&lt;/textbox1-&gt;&lt;textbox1-&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;private&lt;/span&gt;: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/textbox1-&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;//Con este For se llenan de espacios en blanco todos los valores de los arreglos Char para que no queden valores de procesos anteriores. &lt;/span&gt;&lt;br /&gt;             &lt;span style="color: rgb(51, 51, 255);"&gt;for&lt;/span&gt;(&lt;span style="color: rgb(51, 51, 255);"&gt;int&lt;/span&gt; i=0;i&amp;lt;50;i++){&lt;br /&gt;                 juan[i]=' ';&lt;br /&gt;            }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;textbox1-&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;                 &lt;span style="color: rgb(51, 51, 255);"&gt;               for&lt;/span&gt; (&lt;span style="color: rgb(51, 51, 255);"&gt;int&lt;/span&gt; i = 0 ; i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/textbox1-&gt;&amp;lt;&lt;textbox1-&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;textBox1-&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/textbox1-&gt;&amp;gt;&lt;textbox1-&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Text-&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/textbox1-&gt;&amp;gt;&lt;textbox1-&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Length ;i++)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;                    juan[i] =  textBox1-&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/textbox1-&gt;&amp;gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Text[i];            &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;                }&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;text-&gt;&lt;br /&gt;&lt;/text-&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Código para el button2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/div&gt; &lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt; &lt;div style="text-align: justify;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;private&lt;/span&gt;: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {&lt;br /&gt;     textBox2-&amp;gt;Text="";&lt;br /&gt;     &lt;span style="color: rgb(51, 51, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(51, 51, 255);"&gt;int &lt;/span&gt;i = 0 ; i&amp;lt; 20; i++)&lt;br /&gt;         textBox2-&amp;gt;Text += Char::ToString(juan[i]); &lt;br /&gt;     }&lt;br /&gt;&lt;text&gt;&lt;/text&gt;&lt;/div&gt; &lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Explicación:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt; &lt;div style="text-align: justify;"&gt;El usuario del programa va a escribir algo en el textBox1. Pero todo lo que el usuario escriba en el textBox1 es por defecto considerado y tomado como tipo String. Pero nosotros queremos convertir todo lo que esté en el textBox1 de su valor por defecto String al tipo Char. Por tanto lo primero es declarar un arreglo con tipo Char, así:&lt;br /&gt;&lt;br /&gt;char juan[20];&lt;br /&gt;&lt;br /&gt;Ahora estamos listos para escribir código en el button1, y su trabajo será transformar la información String introducida por el usiario desde el button1, al tipo Char.&lt;br /&gt;&lt;br /&gt;Una vez que la información ha sido convertida de String a Char, ya tenemos datos en nuestro arreglo Char, pero no podemos verla porque está solamente en memoria. Si queremos ver en un textBox lo que está en nuestro arreglo Char, tenemos que convertir lo que está en el arreglo, de Char a String, ¿por qué?, bien porque un textBox sería capaz de imprimir fácilmente un tipo String, pero nunca un tipo Char. Imprimir directamente un elemento Char en un textBox  es simplemente imposible. Por ello el button2 de nuestro programa sería el responsable de realizar esa conversión de Char a String y finalmente veremos en el textBox2 lo que se ha guardado en nuestro arreglo Char.&lt;br /&gt;&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;Jaime Montoya&lt;br /&gt;jaimemontoya@jaimemontoya.com&lt;br /&gt;&lt;a href="http://www.jaimemontoya.com"&gt;www.jaimemontoya.com&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8373220483460808467-4095505783232518874?l=chartostringusingvisualcmasmas2005.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8373220483460808467/posts/default/4095505783232518874'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8373220483460808467/posts/default/4095505783232518874'/><link rel='alternate' type='text/html' href='http://chartostringusingvisualcmasmas2005.blogspot.com/2007/04/converting-from-char-to-string-on.html' title='Converting from Char to String on Visual C++ 2005'/><author><name>Jaime Montoya</name><uri>http://www.blogger.com/profile/16823894261113468942</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://3.bp.blogspot.com/_xxqD9isjXyY/S6xjpG1cqfI/AAAAAAAAO18/D6l_ssNuNNA/S220/jaimemontoya.jpg'/></author></entry></feed>
