peter70 peter70 - 1 month ago 15
Vb.net Question

Mid as target of an assignment

I try just an old VB application in c# to convert, while I've encountered this line of code:

Mid(strData, intPosition + 1, intLenght) = strValue


How can it be translated into c#?

Answer

You would have to combine Remove and Insert, something like:

strData.Remove(intPosition, intLenght).Insert(intPosition, strValue);

The above assumes that the length of strValue was equal to intLenght. If strValue might be longer, then to replicate the Mid statement, we would need to do:

strData.Remove(intPosition, intLenght)
       .Insert(intPosition, strValue.Substring(0, intLenght));
Comments