Var curMeta As String = "content=""SBF borrowed $546M from Alameda to fund Robinhood"""
Var removePattern As String = "^\s*data-n-head\s*=\s*" // only at beginning and can have spaces around
Var re As New RegEx
re.SearchPattern = removePattern
re.ReplacementPattern = ""
// *** Tests ***
Var s As String = re.Replace("data-n-head="+curMeta)
If s <> curMeta Then MessageBox("Assertion 1 Failed")
s = re.Replace(" data-n-head = "+curMeta)
If s <> curMeta Then MessageBox("Assertion 2 Failed")
curMeta = "content=""SBF borrowed the string 'data-n-head=' to fund Robinhood"""
s = re.Replace("data-n-head="+curMeta)
If s <> curMeta Then MessageBox("Assertion 3 Failed")
MessageBox "If no assertion has been fired, tests were OK"
Quit
I tried the following code and it works as you expected:
Var CurMeta as String = "data-n-head="+"content=""SBF borrowed $546M from Alameda to fund Robinghood"""
Var curRemove as string = "data-n-head="
var pos as integer = CurMeta.IndexOf(curRemove)
if pos <> -1 then
Break
CurMeta = CurMeta.Trim(curRemove)
end if
Break
First break shows data-n-head= in CurMeta
Second break, is gone:
Maybe you have invisible characters and that is why Trim is not working for you?
I agree, I’m just testing OP code and it works here.
I just don’t like a thread with title “XYZ doesn’t work” and talk about the docs or better code to do things (sending the message that in fact XYZ is broken) when XYZ is working. That’s all.
I don’t understand how you can write that. It is MyString2 = MyString1.Trim or MyString2 = Trim(MyString1) but what is MyString2 = MyString1.Trim(MyString3)???