- Home
·
- String Manipulation
·
- This is an update to my earlier ShiftString function. I had one digit wrong by one, thus sometimes
This is an update to my earlier ShiftString function. I had one digit wrong by one, thus sometimes
This is an update to my earlier ShiftString function. I had one digit wrong by one, thus sometimes giving wrong results. This one has been
Rate This is an update to my earlier ShiftString function. I had one digit wrong by one, thus sometimes
(1(1 Vote))
ByVal PositionToShift As Integer, _
ByVal NumChars As Integer, _
ByVal PlacesToShift As Integer) As String
' Variable declaration
Dim ShiftedString, SubString As String
Dim stringLength As Integer
ShiftedString = OriginalString
stringLength = ShiftedString.Length
' Error-checking section
If (NumChars < 0) Or (NumChars >= stringLength) Then
Return ShiftedString
End If
If PlacesToShift = 0 Then
Return ShiftedString
End If
If PositionToShift < 0 Or PositionToShift >= stringLength Then
Return ShiftedString
End If
If (PositionToShift + NumChars + PlacesToShift > stringLength) Or _
(PositionToShift + PlacesToShift < 0) Then
Return ""
End If
' Get substring to shift
SubString = ShiftedString.Substring(PositionToShift, NumChars)
' Remove substring from original string
ShiftedString = ShiftedString.Remove(PositionToShift, NumChars)
' Insert substring into new position
ShiftedString = ShiftedString.Insert(PositionToShift + PlacesToShift, _
SubString)
Return ShiftedString
End Function
This is an update to my earlier ShiftString function. I had one digit wrong by one, thus sometimes Comments
No comments yet — be the first to post one!
Post a Comment