WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

File Operations

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Write a Variety of Quote Marks to Files

Keywords:    quote quotes quote marks single quotes double quotes

Question:

I have a program that needs to set ini lines like the following:
[section]
this="that's it"
this1="that`s it again"
this2="that'`s it for good"
the data values are directory or file names that can contain either or both of the single forward or single backward quote, as both of these are acceptable file/dir name characters.

I also need the double quote to go around the entire entry.

Is there any way to set the quote to another mark, that is not an acceptable dir\file name character? I am not sure what characters are reserved from being used for dir\file names.

Answer:

In WinBatch double-quotes ( " ), single-quotes ( ' ), and back-quotes ( ` ) call all be used as quote marks.
a=`"quoted string"`
Message('A quoted string',a)

Question (continued):

The three available quotes don't leave me the flexibility I need. both single quotes are acceptable file or dir characters. I need to set INI settings like:
[section]
dir1="Mike's Stuff"
In this case I use the ` quote as the "wrapper" as both " and ' are used in the value filed. But I would need to dynamically change the wrapper if the directory or filename had the ` character. For example I cannot set
[section]
dir1="Mike's `stuff`"
as all thre quotes are in use. The commands
INIWrite("section","dir1",""Mike's `stuff`"")
INIWrite("section","dir1",'"Mike's `stuff`"')
INIWrite(`section","dir1",`"Mike's `stuff`"`)
all fail with "illegal character" error.

Although a dir or file can't have a " in the name, a " is part of many INI and registry entries and thus, can't be used as the wrapper. Kind of a catch-22.

Answer:

Change quotes to the wording #squote# for a single quote, #dquote# for a double quote and #bquote# for a back quote.
MydefaultAnswer=strcat("single quote '",'double quote ",',"and back quote `")
inifile = "c:\test.ini"
a=askline("Quote converter","Enter your text with back, single, or double quotes.", MydefaultAnswer)

a=StrReplace (a,"'","#squote#")
a=StrReplace (a,'"',"#dquote#")
a=StrReplace (a,"`","#bquote#")
INIWritePvt("section", "key", a, inifile)

Display (5,"My Variable with quoted text","%a%")

a = IniReadPvt("section", "key", , "", inifile)
a=StrReplace (a,"#squote#","'")
a=StrReplace (a,"#dquote#",`"`)
a=StrReplace (a,"#bquote#","`")

Display (5,"My Variable information back again",a)
Or you can build the variables up piecemeal as follows, or see below (b)

a)

a1=strcat( `"Mike's `, '`stuff`"')

a2="Mike's `stuff`"
a2=strcat( '"', a2, '"')

INIWrite("section","dir1",a1)
INIWrite("section","dir2",a2)
b)
;Use a different character for say backquotes
;and flip it at the last second. Lets say
; we use a \ instead of a backquote.

a3=`"Mike's \stuff\"`
a3=StrReplace(a3, "\", "`")
IniWrite("section","dir3",a3)

Article ID:   W13246
Filename:   Write Various Quote Marks to Files.txt
File Created: 2008:02:27:09:18:32
Last Updated: 2008:02:27:09:18:32