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 commandsINIWrite("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:
Then you will probably need to 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: W13246Filename: Write Various Quote Marks to Files.txt