desiredforsome
asked on
VB6 string replace
So I have an issue that I cannot figure out.
I have a string that contains email addresses
I.E
I have another string set of
I.E
I want to remove the second string set from string 1. Even though they are not in order. I don't know how to figure this one out. I would assume that i need to separate the second string into an array perhaps and do a foreach loop which removes them from string one.
Scratching my head at this moment.
I have a string that contains email addresses
I.E
test@test.com, test@123.com, test@456.com
I have another string set of
I.E
test@123.com, test@test.com
I want to remove the second string set from string 1. Even though they are not in order. I don't know how to figure this one out. I would assume that i need to separate the second string into an array perhaps and do a foreach loop which removes them from string one.
Scratching my head at this moment.
This may help.
Sub Remove()
Const delimiter As String = ","
Dim iterStr As Variant
Dim mainlist As String
Dim sublist As String
Dim split_sublist() As String
mainlist = "test@test.com, test@123.com, test@456.com"
sublist = "test@123.com, test@test.com"
split_sublist = Split(sublist, delimiter)
For Each iterStr In split_sublist
'clean iterStr the way you want.
iterStr = Replace(iterStr, " ", "")
mainlist = Replace(mainlist, iterStr & delimiter, "")
mainlist = Replace(mainlist, iterStr, "")
Next iterStr
'clean mainlist the way you want.
mainlist = Trim(mainlist)
End Sub
ASKER
For Hakan, I get a Mismatch on the FOr each line
For Guy -
I dont see where this outputs to a string. Only an array.
For Guy -
I dont see where this outputs to a string. Only an array.
ASKER
Also get unexptected text on Guy.
Can you please write me what error is? I don't have vb6 installed. I try it in excel VBA.
Also please change "Dim iterStr As Variant" to "Dim iterStr" and try.
Also please change "Dim iterStr As Variant" to "Dim iterStr" and try.
ASKER
So the whole error is Error: 10080 (10080) Type Mismatch Line number 17. This is also after I have changed the dimension.
It is on the "For Each" line of code.
It is on the "For Each" line of code.
Can you please now change it to "Dim iterStr As String" and try?
ASKER
I get Error 0 Var is already defined as a different type line 17 (that is on the For Each line)
Please try this.
Sub Remove()
Const delimiter As String = ","
Dim mainlist As String
Dim sublist As String
Dim split_sublist() As String
mainlist = "test@test.com, test@123.com, test@456.com"
sublist = "test@123.com, test@test.com"
split_sublist = Split(sublist, delimiter)
For Each iterStr as String In split_sublist
'clean iterStr the way you want.
iterStr = Replace(iterStr, " ", "")
mainlist = Replace(mainlist, iterStr & delimiter, "")
mainlist = Replace(mainlist, iterStr, "")
Next iterStr
'clean mainlist the way you want.
mainlist = Trim(mainlist)
End Sub
ASKER
Error 0
Expeting 'In' line number 16 (Same line as always). I am try to figure this out with research and and pulling hair out.
Expeting 'In' line number 16 (Same line as always). I am try to figure this out with research and and pulling hair out.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OMG AWESOME!!!!
Open in new window