I'd like to save input of an unknown string length into an array. How do I make so that it will result like following:
string a = "ABCA";
char[] array;
array = a.ToCharArray(0, a.length);
foreach (char c in array) {
switch(c) {
case 'A':
into2ndarray = 1;
break;
case 'B':
into2ndarray = 2;
break;
case 'C':
into2ndarray = 3;
break;
}
}
int[] into2ndarray //the result will be used for another calculation
So, the expected result from this is {1, 2, 3, 1}
Any idea on how to achieve this? thank you.
a.Lengthwill give you the length of the string,array.Lengthwill give you the length of the array, you can even calla.ToCharArray();without any arguments and it will take care of this for you without manually specifying0,a.Length. What's the issue?into2ndarraythat you need?var alphabet = "abcdefghijklmonp.."and use index of +1 to get your number