peter70 peter70 - 3 months ago 24 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#?


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));