How can I convert char to int (Int32) in multidimensional array?

A

Allen Maki

Hi Everybody,

I am new to VC.NET and I need your help.



I would like the array to print characters as '.'s (dots) instead of 0s as
in (see below in front of //------>>>>>.

I tried to use casting like this:

multArray2[m,n] = int ('.');

If these are confusing. My question is how to use multidimensional array to
print characters instead of int





//Declare loop counters

int m,n,o;

//Create multidimensional array of int32s

Int32 multArray2[,] = new Int32[6,7];

//Fill the array with value

for (m=0; m<multArray2->GetLength(0); m++)

for (n=0; n<multArray2->GetLength(1); n++)

{

//--------->>>>> multArray2[m,n] = 0 ;

}



Thanks.
 
G

Guest

I would like the array to print characters as '.'s (dots) instead of 0s as
in (see below in front of //------>>>>>.

Int32 val = '.';
Console.WriteLine(Convert::ToChar(val));

this will print a '.'
val is an integer that will receive the decimal ASCII value of the '.'
character which is 46.
If you would not convert to char, the value 46 would be printed, since that
is the default value to string conversion for an Int32.

you can simply initialize each value in your matrix to '.' and when you want
to print it you use a comniation of Write and WriteLine to print your matrix
to the screen.

be aware that converting 12345678 to Char will not work, since characters
are limited to 8 bits.

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"
 
A

Allen Maki

Thanks Bruno,
I will try it and let you know.


Bruno van Dooren said:
Int32 val = '.';
Console.WriteLine(Convert::ToChar(val));

this will print a '.'
val is an integer that will receive the decimal ASCII value of the '.'
character which is 46.
If you would not convert to char, the value 46 would be printed, since
that
is the default value to string conversion for an Int32.

you can simply initialize each value in your matrix to '.' and when you
want
to print it you use a comniation of Write and WriteLine to print your
matrix
to the screen.

be aware that converting 12345678 to Char will not work, since characters
are limited to 8 bits.

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top