VB.NET编程日记

VB.NET编程日记

1、FOR循环的郁闷
VB.NET中的FOR循环中改变了界限的数值,还只是记住原来的界限,考虑以下程序,是把一个字符串中的非字母去掉:
 1          Dim  ss  As   String   =   " Gogo No Kocha (Milk Tea) (500ml) - Small "
 2          Dim  pos2  As   Integer   =  ss.Length
 3          Dim  i  As   Integer
 4          Dim  ch  As   Char
 5          For  i  =   0   To  pos2  -   1
 6              If  i  >=  pos2  -   1   Then   Exit   For
 7             ch  =  ss.Chars(i)
 8              If  ch.IsLetter(ch)  =   False   And  ch  <>   "   "   Then
 9                 ss  =  ss.Remove(i,  1 )
10                 i  -=   1
11                 pos2  -=   1
12              End   If
13          Next
14         ss  =   " Gogo No Kocha Milk Tea ml  Small "
如果不加上第6行,会死得很惨。

你可能感兴趣的:(VB.NET编程日记)