[英]How to find a position in a integer
如果我有一个整数,例如11110011。我将如何找出每个位置的数字,以便可以使用它们计算出一些东西。 谢谢
将其强制转换为String,然后使用string方法在特定位置查找int。
如果您愿意,可以随时阅读一些有关运算符的信息。 无论如何,我会使用Mod 10
的循环并在每次迭代中除以10。
伪代码:
Given number
While number is not zero
Get the mod 10 of the number
... Do what you need to do with it - that's the digit
Divide by 10.
Repeat.
Done.
例如:
Dim yourNumber As Integer = 12930 // for example.
While index >0
Dim digit As Integer = yourNumber Mod 10
Debug.Write(digit.ToString & " ")
index /= 1
End While
将写所有数字,并用空格分隔:
output: 1 2 3 9 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.