View Single Post
  #1  
Old 06-27-2019, 02:04 AM
slouw slouw is offline
Registered User
 
Join Date: Nov 2005
Posts: 166
Inverted comma literal

Related to this forum post
I have a script that turns off logging, changes the log file name and turns on logging again.
In this script is the fragment below to replace certain defined characters in a string with a "_".
The string is the new logfile name.
The illegal characters are those that cannot be included in a filename.
All works well accept that this script fragment does not remove a double quote
"
resulting in an error.
Any ideas how I can represent the double quote as a literal so code fragment will do what is intended?

With much gratitude...

Code:
IllegalChars ="|/\<>:*"""
## Problem here is that each illegal char is searched for only once.
## When 2 senak in we have a problem
for char in IllegalChars:
    if char in CommandStr:
        ## .replace method should replace ALL occurrences.
        ## Seems this is not happening
        CommandStr = CommandStr.replace(char, "_")
        writeB("00380 **PRESENT**                 :" + CommandStr + "<>" + "   " + char)
        ## crt.Dialog.MessageBox("00380 **PRESENT** :" + CommandStr + "<>" + "   " + char)
    else:
        ## crt.Dialog.MessageBox("00390 No          :" + CommandStr + "<>" + "   " + char)
        writeB("00390 No                          :" + CommandStr + "<>" + "   " + char)

Last edited by jdev; 07-08-2019 at 09:29 AM. Reason: wrap code in [code] blocks
Reply With Quote