今天和同事聊天时,他说出了一些奇怪的想法。
他提到了一种处理来自vb6的字符串的“秘密”方法,大致如下:
他提到了一种处理来自vb6的字符串的“秘密”方法,大致如下:
Dim strSomeString as String
strSomeString = "i am phat"
Mid$(strSomeString, 6,4) = "hack"
这将把i am hack
放入strSomeString
中。
虽然对于VB6支持这样的奇特性感到惊讶,但当我读到它在VB.Net中也得到了支持时,我完全被吹走了(可能是为了与旧代码兼容)。
Dim TestString As String
' Initializes string.
TestString = "The dog jumps"
' Returns "The fox jumps".
Mid(TestString, 5, 3) = "fox"
' Returns "The cow jumps".
Mid(TestString, 5) = "cow"
' Returns "The cow jumpe".
Mid(TestString, 5) = "cow jumped over"
' Returns "The duc jumpe".
Mid(TestString, 5, 3) = "duck"
我的问题是: 它在技术上如何工作的?在这种特定情况下,Mid
起到了什么作用?(方法?函数?扩展方法?)