Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-27-2019, 01:04 AM
slouw slouw is offline
Registered User
 
Join Date: Nov 2005
Posts: 143
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 08:29 AM. Reason: wrap code in [code] blocks
Reply With Quote
  #2  
Old 07-06-2019, 09:47 AM
gregg gregg is offline
Registered User
 
Join Date: Oct 2010
Posts: 51
Try either:

Code:
IllegalChars ='|/\\<>:*"'
Or:

Code:
IllegalChars ="|/\\<>:*\""
In Python, certain string literals need to be escaped, such as \ and "

If you wrap the string in double quotes (") then you need to escape double quotes (\"), however, if you wrap a string in single quotes ('), then you don't need to escape double quotes, but would need to escape single quotes (\')

see: https://docs.python.org/2.0/ref/strings.html
Reply With Quote
  #3  
Old 07-07-2019, 07:49 PM
slouw slouw is offline
Registered User
 
Join Date: Nov 2005
Posts: 143
Will do thanks fro reply....
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 06:16 AM.