[Closed] Remove ESC from incoming string data
I have a function that uses memStream.readLine() to get data from 3rd party data sources (text files). Now I’ve encountered a problem I’ve never seen before.
Here is some pseudo-code:
Incoming string looks like this in Notepad++ (but uses little arrows in Notepad):
connections
{
"OnUser1" "target1e[b]ESC[/b]SetParente[b]ESC[/b]parentObj1[b]ESC[/b]e0[b]ESC[/b]e-1"
"OnUser2" "target1e[b]ESC[/b]SetParente[b]ESC[/b]parentObj2[b]ESC[/b]e0[b]ESC[/b]e-1"
"OnUser3" "target1e[b]ESC[/b]SetParente[b]ESC[/b]parentObj3[b]ESC[/b]e0[b]ESC[/b]e-1"
"OnUser4" "target1e[b]ESC[/b]SetParente[b]ESC[/b]parentObj4[b]ESC[/b]e0[b]ESC[/b]e-1"
}
(The characters did not paste properly into the form, so below is an actual image.)
That string is assigned to IncomingString in the code below:
memStreamString = memStreamMgr.openString IncomingString
while memStreamString.eos() == false AND memStreamString.peekToken() != undefined do (
memStreamString.skipSpace()
theLineC= (memStreamString.readLine())
print theLineC
--This will print the text in the MAXScript listener
filterString theLineC " "
--This will stop the code from executing and print **interrupted** in the Maxscript listener
)
So it appears this incoming data is using the character code that represents the ESC key on the keyboard.
I do not know how to sanitize this so that I can use it.
I find it odd that I can print the code but as soon as I try to run string functions that let me extract the data I want, Max stops executing and prints:
** interrupted **
I tried adding this code to the top of the parser:
escapeEnable = false
But that did not help (and according to the docs, is now defaulting to false anyway).
OK… I found a solution:
replacementString = " " --set to whatever is best for needs
cleanString = substituteString taintedString "\x1b" replacementString