Dim Str As String = "0 0" & Chr(10) & Chr(13) & vbcrlf & "0"
Dim Int As Integer
Output.Show("【第1次输出】")
With Str
Str = Str.Replace(vbcrlf,Chrw(12276))
Str = Str.Replace(Chr(13),Chrw(12276))
Str = Str.Replace(Chr(10),Chrw(12276))
Int = Str.Length
For I As Integer = 0 To Int - 1
Output.Show(Ascw(Str.Chars(I)))
Next
End With
Output.Show("【第2次输出】")
Str = "0 0" & Chr(10) & Chr(13) & vbcrlf & "0"
With Str
Str = .Replace(vbcrlf,Chrw(12276))
Str = .Replace(Chr(13),Chrw(12276))
Str = .Replace(Chr(10),Chrw(12276))
Int = Str.Length
For I As Integer = 0 To Int - 1
Output.Show(Ascw(.Chars(I)))
Next
End With
【输出结果】
【第1次输出】
48
32
48
12276
12276
12276
48
【第2次输出】
48
32
48
10
13
13
10
48
【问题】
Chr(10)在第2次是多余的,这问题搞了我昨天一下午,现在汇报给组织,忘改进!
这玩意不是bug,再说了这个是.net自身的语法,不是foxtable创造的。
Str = Str.Replace(vbcrlf,Chrw(12276))和Str = .Replace(vbcrlf,Chrw(12276))改变的都是外部的str变量,其实with str内部有一个独立的变量使用,一直没有变过
with 和 end with之间形成了一个独立的程序域,可以把with理解为一个sub方法。自行测试一下下面代码,原理是一样的
全局代码
Public Sub abc(str As String)
Dim s As String = str
s = s.replace("1","A")
End Sub
Public Sub abc2(str As String)
str = str.replace("1","A")
End Sub
命令窗口测试
Dim str As String = "1"
abc(str)
Output.Show(str)
abc2(str)
Output.Show(str)