Modifying an array based on a structure within a function
Hi guys
I've run into a bit of an issue which I'm struggling with and wonder if anyone can give me an idea of what I'm missing.
I have an array based on a structure which in turn has three string values. I'm unable to use Replace to remove or replace a character in one of those strings (.Value) - it does nothing.
If I manually loop through the string and look for the the character to be replaced, I can delete or replace without issue.
I get no errors and the code continues on - just Replace has no effect.
Any thoughts? Is this an issue due to Replace not being able to dela with the structure?
Here's the code in question (only):
Code:
Public Module Module_Definitions
Public Structure CMDlineDBstruct
Public Value As String
Public StartPos As Integer
Public EndPos As Integer
End Structure
Public CMDlineDB(100) As CMDlineDBstruct
End Module
' The following does *not* work
Public Class CmdParser
Public Sub RemoveChrFromCMDlineDB(c As String)
For i As Integer = 1 To CMDlineCount
Replace(CMDlineDB(i).Value, c, "")
Next
End Sub
End Class
' Where-as the following works
Public Class CmdParser
Public Sub t(c As String)
For i As Integer = 1 To CMDlineCount
For k As Integer = 1 To Len(CMDlineDB(i).Value)
If Mid(CMDlineDB(i).Value, k, 1) = c Then CMDlineDB(i).Value = Left(CMDlineDB(i).Value, k - 1) & Mid(CMDlineDB(i).Value, k + 1)
Next k
Next i
End Sub
End Class
Re: Modifying an array based on a structure within a function
Did you read the documentation for Replace?
https://docs.microsoft.com/en-us/dot...e?view=net-5.0
"Returns a new string ..."
Re: Modifying an array based on a structure within a function
Quote:
Originally Posted by
OptionBase1
You are correct and it now works. That's annoying :D.
Just to explain: I honestly tried that at the beginning and it didn't seem to work, but there was probably something else wrong with the calling routine and I wasn't thorough enough at the time.
Also, there is a version of Replace which works in the way I was trying in VBA so I wonder if I saw that at some point.
Anyway, thanks for the pointer. I feel a tad silly. :blush:.
Re: Modifying an array based on a structure within a function
There is the .Net String.Replace function, and also the legacy Replace function...