Today, while talking with my colleague, something odd came out of his mind.
A "secret" way to handle string coming from vb6, which was like:
Dim strSomeString as String
strSomeString = "i am phat"
Mid$(strSomeString, 6,4) = "hack"
This would put i am hack
inside strSomeString
.
While being surprised of such oddity being supported in vb6, I was totally blown when I read that it is supported in VB.Net too (probably for compatibility with old code).
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"
My question is: how is it technically working? What is Mid
acting like in that particular situation? (method? function? extension method?)