C#将char转换为int [英] C# convert char to int
问题描述
这是我的代码,我希望有mapfull map *的东西,但它的ASCII(或其他东西),我想把它变成正常。 be1 / 2/3是由81个字符长的数字组成的字符串(例如:79456123 ...)。你能帮助我吗?
This is my code and i want to have the mapfull map* stuff but its in ASCII(or something) and i want to turn it "normal". be1/2/3 are strings that are consist of an 81 char long numbers (example: 79456123...). Can you help me?
int ind1 = 0;
int ind2 = 0;
int ind3 = 0;
//MessageBox.Show(be1);
for (int i = 0; i <= 8; i++)
{
for (int j = 0; j <= 8; j++)
{
mapFull[i, j] = be1[ind1++];
mapInitial[i, j] = be2[ind2++];
mapCurrent[i, j] = be3[ind3++];
}
}
推荐答案
假设mapFull,mapInitial和mapCurrent是int的数组
,那么这应该做:
Assuming mapFull, mapInitial and mapCurrent are arrays ofint
, then this should do:
mapFull[i, j] = (int)be1[ind1++] - '0';
mapInitial[i, j] = (int)be2[ind2++] - '0';
mapCurrent[i, j] = (int)be3[ind3++] - '0';
编辑:请记住这个解决方案是愚蠢的 - 如果字符串中有非数字字符,则不会出现错误/异常。因此,在使用之前,您必须确保字符串纯粹由数字组成。但你的问题就是这样,所以我建议采用这种方法。
Keep in mind that this solution is "stupid" - if there are non-digit characters in your string, you won't get an error / exception. So you have to ensure that the strings are purely made of digits before using this. But your question reads like that is the case, so I suggested this approach.
这篇关于C#将char转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!