..user must enter a string of numbers and i split
that string to get an array of strings..
how can i convert string[] to int[] ?
C# arraysCan i convert arrays of type string to int?
Page 1 of 1
4 Replies - 473 Views - Last Post: 13 September 2010 - 04:00 AM
Replies To: C# arrays
#2
Re: C# arrays
Posted 12 September 2010 - 07:10 AM
http://www.asciitable.com/
Take particular note of the range of characters between decimal 48 and 57. Use that information to do what you are attempting.
Take particular note of the range of characters between decimal 48 and 57. Use that information to do what you are attempting.
#3
Re: C# arrays
Posted 13 September 2010 - 12:51 AM
yosuke06, on 12 September 2010 - 06:00 AM, said:
..user must enter a string of numbers and i split
that string to get an array of strings..
how can i convert string[] to int[] ?
that string to get an array of strings..
how can i convert string[] to int[] ?
Welcome on board, yosuke06!
Try these code snips
(Next time you need to explain your
task more widely for the better understanding
your problem)
//convert array of letters to array of integers (ascii codes)
string[] sarr = new string[] {"A","B","C","D","E","F","G" ,"H" };
int cnt = sarr.Length;
int[] iarr = new int[cnt];
for (int i = 0; i < cnt; i++)
{
char c = sarr[i].ToCharArray()[0];
iarr[i] = (int)c;
Console.WriteLine("Letter: {0}\tNumber: {1}", sarr[i], iarr[i]);
}
}
...and this one
//convert numeric strings to array of integers
string[] sarr = new string[] {"101","102","103","104","105","106","107","108" };
int cnt = sarr.Length;
int[] iarr = new int[cnt];
for (int i = 0; i < cnt; i++)
{
iarr[i] = Convert.ToInt32(sarr[i]);
Console.WriteLine("String: {0}\tNumber: {1}", sarr[i], iarr[i]);
}
~'J'~
#4
Re: C# arrays
Posted 13 September 2010 - 03:48 AM
fixo, on 13 September 2010 - 02:51 PM, said:
yosuke06, on 12 September 2010 - 06:00 AM, said:
..user must enter a string of numbers and i split
that string to get an array of strings..
how can i convert string[] to int[] ?
that string to get an array of strings..
how can i convert string[] to int[] ?
Welcome on board, yosuke06!
Try these code snips
(Next time you need to explain your
task more widely for the better understanding
your problem)
//convert array of letters to array of integers (ascii codes)
string[] sarr = new string[] {"A","B","C","D","E","F","G" ,"H" };
int cnt = sarr.Length;
int[] iarr = new int[cnt];
for (int i = 0; i < cnt; i++)
{
char c = sarr[i].ToCharArray()[0];
iarr[i] = (int)c;
Console.WriteLine("Letter: {0}\tNumber: {1}", sarr[i], iarr[i]);
}
}
...and this one
//convert numeric strings to array of integers
string[] sarr = new string[] {"101","102","103","104","105","106","107","108" };
int cnt = sarr.Length;
int[] iarr = new int[cnt];
for (int i = 0; i < cnt; i++)
{
iarr[i] = Convert.ToInt32(sarr[i]);
Console.WriteLine("String: {0}\tNumber: {1}", sarr[i], iarr[i]);
}
~'J'~
hey..thanks for the code snips and also for
the tip..i'll make sure to explain my task
much clearer next time..
..the code snips helped a lot'..,
~tnx
#5
Re: C# arrays
Posted 13 September 2010 - 04:00 AM
yosuke06, on 13 September 2010 - 02:48 AM, said:
fixo, on 13 September 2010 - 02:51 PM, said:
yosuke06, on 12 September 2010 - 06:00 AM, said:
..user must enter a string of numbers and i split
that string to get an array of strings..
how can i convert string[] to int[] ?
that string to get an array of strings..
how can i convert string[] to int[] ?
Welcome on board, yosuke06!
Try these code snips
(Next time you need to explain your
task more widely for the better understanding
your problem)
//convert array of letters to array of integers (ascii codes)
string[] sarr = new string[] {"A","B","C","D","E","F","G" ,"H" };
int cnt = sarr.Length;
int[] iarr = new int[cnt];
for (int i = 0; i < cnt; i++)
{
char c = sarr[i].ToCharArray()[0];
iarr[i] = (int)c;
Console.WriteLine("Letter: {0}\tNumber: {1}", sarr[i], iarr[i]);
}
}
...and this one
//convert numeric strings to array of integers
string[] sarr = new string[] {"101","102","103","104","105","106","107","108" };
int cnt = sarr.Length;
int[] iarr = new int[cnt];
for (int i = 0; i < cnt; i++)
{
iarr[i] = Convert.ToInt32(sarr[i]);
Console.WriteLine("String: {0}\tNumber: {1}", sarr[i], iarr[i]);
}
~'J'~
hey..thanks for the code snips and also for
the tip..i'll make sure to explain my task
much clearer next time..
..the code snips helped a lot'..,
~tnx
I glad to help where I can.
Happy coding
~'J'~
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|