C# newbie.. accessing strings by index, assigning NULL at the end of a char array

char , array , index Montreal, Canada
  • 12 years ago
    Hi I've begun learning C# and begun writing some code that would normally work in C and C++: protected void Button1_Click(object sender, EventArgs e) { char[] text1,text2; int ii=0; text1 = TextBox1.Text.ToCharArray(); while (text1[ii]!= 0) { //text2.[ii] = caract; text2[ii] = text1[ii]; ii++; } text2[ii] = 0; ****** TextBox2.Text = text2.ToString(); } This won't compile and for the line ****** return the error: Constant value '0' cannot be converted to a 'char' I've tried to assign it to null, "" , '', but none of them work. thanks NYB
  • 12 years ago
    you may need ChrW(0) or Chr(0) and for while condition maybe Asc(text1[ii])>0

    *remember that conversion between char and integer is not automatic*

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'” - Isaac Asimov