Output Inverted commas within a string

Greetings
I have a script with the following output which works.

cmd.RunCommand("set hideFILTERFILENAME regex:" + Str_Filter_ENTERED)

I want to add inverted commas to the output marked by SSSS and EEEE below:

cmd.RunCommand("set hideFILTERFILENAME SSSSregex:" + Str_Filter_ENTEREDEEEE)

How would I express that correctly?
I have tried various combinations including double inverted commas "" but no luck....

Assuming we're talking about JScript here:

https://www.google.com/search?q=javascript+string+quotes

Go triple! A joy reserved for the distinguished VBscript connoisseur :wink:

Haha thnaks guys
It is late here will try in the morning.... :slight_smile:

With sincere apologies we are in fact talking VBSCRIPT sigh!!!!
I have worked on this but cannot get it working on my main script.
So I have a debugging script below (which is working but 2 things I don't understand may be relevant to my main script.

QUERY 1 Toggle Effect

(Hm I did not know I could make a header like that....)
Consider the Folder Options >> Show Filter >> File Names field.
This is blank to start with.
As expected after running the script the field for the current folder tab is not populated with "Bne Airport" as per the script.
The folder tab is now filtered so only file names containing the string are visible.
That is as expected
But when you run it again it has the effect of removing the string from the field above.
Run it again (3rd time) and the filtering effect is created again (field is populated)
Why this toggling effect?

' VBSCRIPT
'
'Option Explicit
Function OnClick(ByRef clickData)
' ---------------------------------------------------------
DOpus.ClearOutput
Set cmd = clickData.func.command
Str_Filter_ENTERED = "Bne Airport"
DOpus.Output("set SHOWFILTERFILENAME ""regex: " + Str_Filter_ENTERED + """")
cmd.RunCommand("set SHOWFILTERFILENAME ""regex:" + Str_Filter_ENTERED + """")
End Function

QUERY 2 Removing Trailing Inverted Commas have not effect

Notice below I have removed the trailing inverted commas.
i.e. the + """" has been removed
This has no effect - the script still works. Why? Maybe the set command is clever enough to close the inverted commas itself?
The toggle effect is unchanged.

'
'Option Explicit
Function OnClick(ByRef clickData)
' ---------------------------------------------------------
DOpus.ClearOutput
Set cmd = clickData.func.command
Str_Filter_ENTERED = "Bne Airport"
DOpus.Output("set SHOWFILTERFILENAME ""regex: " + Str_Filter_ENTERED)
cmd.RunCommand("set SHOWFILTERFILENAME ""regex:" + Str_Filter_ENTERED)
End Function

Isn't this Opus' standard behavior?

I'd say yes. You might run into problems if the string ends with a space, because that might get ignored.

*IXP thank you for continued help it is greatly appreciated.
The above troubleshooting script was an attempt to zero in on the issue.
I got different results with my troubleshooting script to my main script for reasons I do not understand.
My main script pops up a dialog box in which some text can be typed in.
Upon hitting ok the current lister tab file display is filtered in a manner similar to that described above.
It works fine unless there is a space in the text.
In an effort to accommodate spaces I have added the changes highlighted in yellow in the screenshot below.
So far as I can work out that is exactly what works in my troubleshooting script above.
But it breaks my main script.
Any pointers would be greatly appreciated.
Sorry for the VB this is an old script!!
Full script is below the screenshot.....

// 2019-01-29 Close Current Layout
// Original post from Leo
// 2020-12-09 Edit for Filtering purposes
// 2020-12-09 Want to add OR feature. Not started at this point

// 2020-12-11 Prompts with text field prepopulated with existing filter
//            Upon andit and Ok filter is adjusted accordingly
//            File and folder show filters set the same
//            RegEx file always set (i.e. checked) for both File and Folder show filter
// 2021-07-26 var cmd = clickData.func.command()

function OnClick(clickData)
{
	DOpus.ClearOutput
	DOpus.Output ("000100 Start")
//  var cmd = DOpus.Create.Command()
	var cmd = clickData.func.command
	DOpus.Output ("   010  set source=focus")
//  cmd.RunCommand("set source=focus")
//	cmd.SetSource(DOpus.listers)

	var Dlg_Return
	var Str_Filter_ENTERED
	var Str_Filter_Existing = clickData.func.sourcetab.format.show_files
	var Bool_Filter_Existing_RegEx = clickData.func.sourcetab.format.show_files_regex
//   020000
//   020000 Read what is there
//   020000
	DOpus.Output ("020000 Read what is there")
	DOpus.Output ("   010  clickData.func....show_files :" + clickData.func.sourcetab.format.show_files)
	DOpus.Output ("   020  Str_Filter_Existing          :" + Str_Filter_Existing)
	DOpus.Output ("   030  Bool_Filter_Existing_RegEx   :" + Bool_Filter_Existing_RegEx)

//   030000
//   030000 Pre Dialog
//   030000
	DOpus.Output ("030000 Pre Dialog")
	var dlg = clickData.func.Dlg;         // creates a dialog object
    // Nothing happens until you invoke the Show() or getstring() method
	dlg.getstring("Edit Show Filter:",Str_Filter_Existing,0,"OK|Cancel","Show Filter")
	DOpus.Output ("   010  dlg.Input i.e. test entered      :" + dlg.Input)
//   040000
//   040000 Post Dialog
//   040000
	DOpus.Output ("040000 Post Dialog")
	if (dlg.Result == 0)
	{
		DOpus.Output ("   010a dlg.Result                   :" + dlg.Result)
		Str_Filter_ENTERED == ""
		DOpus.Output ("   020a Str_Filter_ENTERED           :" + Str_Filter_ENTERED + " set to empty string")
	}
	else
	{
		DOpus.Output ("   010b dlg.Result                   :" + dlg.Result)
//		Str_Filter_ENTERED = dlg.Input
//		Str_Filter_ENTERED = (typeof dlg.input == 'string') ? 'regex:' + dlg.input : '';
		Str_Filter_ENTERED = (typeof dlg.input == 'string') ? dlg.input : '';
		
		DOpus.Output ("   020b Str_Filter_ENTERED           :" + Str_Filter_ENTERED + " ..assigned from dlg.Input")
	}
//   050000
//   050000 Process Results
//   050000
	DOpus.Output ("050000 Process Results")
	DOpus.Output ("   010  Str_Filter_ENTERED entered   :" + Str_Filter_ENTERED)

           cmd.RunCommand("set SHOWFILTERFILENAME ""regex:" + Str_Filter_ENTERED + """")
      DOpus.Output("   020 set SHOWFILTERFILENAME ""regex  :" + Str_Filter_ENTERED + """")
           cmd.RunCommand("set SHOWFILTERFOLDERS ""regex:" + Str_Filter_ENTERED + """")
	  DOpus.Output("   030 set SHOWFILTERFOLDERS ""regex   :" + Str_Filter_ENTERED + """")
//   060000
//   060000 Sleep
//   060000
	DOpus.Output ("060000 Sleep")
	clickData.func.sourcetab.Update()
	DOpus.Output ("   040  clickData.func....show_files :" + clickData.func.sourcetab.format.show_files)
	DOpus.Output ("   050  Bool_Filter_Existing_RegEx   :" + Bool_Filter_Existing_RegEx)
}

So... you wrote VBscript to troubleshoot JScript?

Then we are back to Leo's first suggestion:

OMG I dont think I have done that!
I am capable of confusing myself in such a way
Any new script I write I do in JScript..... generally I am taking existing scripts and editing them and hisotrically alot of those have been VBScript.
I have looked through the history of this post and I only see VBScript samples/references etc.
Am I mistaken in that?

The "Close Current Layout" script you posted three posts up is JScript, not VBScript.

I cant believe I did that
Well maybe that is why it is not working :slight_smile:
Thanks

Thanks gents
I cannot believe I did that doh!
For anyone who might be interested there are multiple ways I think to included inverted commans in a JSCRIPT string. One of which is a backslash as an escape character.
So these statements are working for me:

// JAVASCRIPT statements working:
 cmd.RunCommand("set SHOWFILTERFILENAME \"regex:" + Str_Filter_ENTERED + "\"")
   DOpus.Output("   020 set SHOWFILTERFILENAME \"regex:  " + Str_Filter_ENTERED + "\"")
 cmd.RunCommand("set SHOWFILTERFOLDERS \"regex:" + Str_Filter_ENTERED + "\"")
   DOpus.Output("   030 set SHOWFILTERFOLDERS \"regex:   " + Str_Filter_ENTERED + "\"")

Thanks again

2 Likes

Another way (easier in simple cases I think) is to use alternate single and double-quotes.

E.g. if you want a double-quote in a string, enclose the string with single quotes.

cmd.RunCommand('set SHOWFILTERFILENAME="regex:' + Str_Filter_ENTERED + '"');

Works the other way too, e.g. DOpus.Output("Hello 'friend'");

1 Like

Opus wants " in its commands, JScript can handle both " and ' (only needs to be consistent per line, not per script). So to avoid having to escape quotes, I reserve the " for Opus and only use ' for JScript.

Here is a nice tool that will format your code this way: CyberChef JavaScript Beautify