我需要在vb.net中执行字符串计数器,就像在整数中一样。
逻辑示例:
$counter=A
loop
print $counter;
$counter +=1;
endloop
输出:A,B,C,D
非常感谢大家。
答案 0 :(得分:0)
您可以使用char
类型执行此操作,虽然不方便,但您可以迭代int来执行此操作。
Dim charNum As Integer = 65
Your loop start code
print Chr(charNum).ToString();
charNum +=1
End loop
答案 1 :(得分:0)
这就是你所追求的:
For Each letter As Char In "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Debug.Print(letter)
Next
这将输出:
A
B
C
...
以下是输出代码的屏幕截图:
答案 2 :(得分:0)
<script type="text/javascript" src="validator.min.js"></script>
<script type="text/javascript">
validator.isEmail('foo@bar.com'); //=> true
//can use this syntax for checking availability of fields in body
if( req.body.email == undefined || req.body.email == '' || req.body.email == null)
{
// do something such as throw error
}
// check for valid or invalid attribute
if(!validator.isEmail(req.body.email)){
// do something such as throw error
}
</script>
当然,您可以在Sub main()
Dim strng As String
Dim counter As Long
strng = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Do While counter < Len(strng)
counter = counter + 1
Debug.Print Mid(strng, counter, 1)
Loop
End Sub
答案 3 :(得分:0)
随意采取您想要的方法:
Const Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim nbLettersToDispay As Integer = 5
For i = 0 To Math.Min(nbLettersToDispay, Letters.Length)
If i <> Math.Min(nbLettersToDispay, Letters.Length) Then
Debug.Print(Letters(i))
End If
Next i
在我的代码中,您只需更改变量nbLettersToDispay
的值,该变量代表要显示的字母数
答案 4 :(得分:0)
这个功能也将表现良好&gt; 26
Dim i As Integer = 0
Do While i < 100
i += 1
Console.WriteLine(excelColumnToLetter(i))
Loop
Function excelColumnToLetter(ByVal iColumn As Integer)
Dim sLetters As String = ""
Dim iTemp As Integer = 0
Do While iColumn
iTemp = (iColumn Mod 26)
If iTemp = 0 Then iTemp = 26
sLetters = Chr(iTemp + 64) & sLetters
iColumn = (iColumn - iTemp) / 26
Loop
Return sLetters
End Function