I have an XML file with about 30000 characters I want to put into a String variable. In that variable, I want to replace certain characters using Replace function.
In the below code neither Replace nor Instr detect the characters I'm looking for. When I shorten the XML to around 3000 characters, the code works.
Strings can be up to 2 billion characters long, so what's going on here?
The only thing that comes to mind is that str is a String and the Instr/Replace require a String Expression as an argument. Is there a limit on the length of String Expression these functions can handle?
Dim str As String
Dim arrInvalidChars() As String
Dim arrValidChars() As String
Dim i As Integer
arrInvalidChars = Split(Expression:="ä, ü, ö, ß, é, ç", Delimiter:=", ")
arrValidChars = Split(Expression:="ae, ue, oe, ss, e, c", Delimiter:=", ")
For i = LBound(arrInvalidChars) To UBound(arrInvalidChars)
On Error Resume Next
Debug.Print InStr(1, str, arrInvalidChars(i), vbTextCompare)
str = Replace(str, arrInvalidChars(i), arrValidChars(i), , , vbTextCompare)
On Error GoTo 0
Next i