cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Happy_Days
Level 7

TextSubSubstitute does not append backslash !

Seems TextSubSetValue or TextSubSubstitute does not associate/replace a trailing backslash. I am trying to replace the TEMP variable in the string but these function always remove the trailing backslash and give wrong result. Can somebody help here:

sNewStr = "-s -a -f1\"\Install.iss\" ;
s1 = sNewStr;
TextSubParseTextSub(sNewStr);
GetEnvVar(sNewStr, sEnvVar);
sEnvVar = sEnvVar + "\\";
TextSubSetValue(s1, sEnvVar, FALSE);
TextSubSubstitute(s1, FALSE);


The above code sets s1 as: "-s -a -f1\"C:\TempInstall.iss\"

whereas, I want to set s1 as: "-s -a -f1\"C:\Temp\Install.iss\"


Regards
Labels (1)
0 Kudos
(5) Replies
RobertDickau
Flexera Alumni

Please use a double backslash inside double-quotes to represent a literal backslash character (the same idea as using \" to represent a double-quote inside a string):

sNewStr = "-s -a -f1\"\\Install.iss\"";
0 Kudos
Happy_Days
Level 7

Thanks Robert. But I am asking this data ("-s -a -f1"\Install.iss\") from end users via a different application...which is then passed to InstallScript. Hence it will be unfair for me to ask my end-users to put "\\" after just because IS does not support it? Please let me know.

Regards
0 Kudos
RobertDickau
Flexera Alumni

If I understand the question: If you pass the string from an external source, it will internally have the backslashes represented correctly; it's only if you have the backslash character directly in InstallScript that you need the double backslash.

Do you have an example of how you're getting the data from the external program? Do you have the same problem when you do that (as opposed to hard-coding the string in InstallScript)?
0 Kudos
spencerw
Level 3

I could not get the TextSubSubstitute to replace the backslash character at all, trailing or otherwise. So I wrote this general replace function. This works for all backslashes (i.e. not just trailing).

Note: I have not done extensive testing on this function; I only made sure it worked for my needs.

////////////////////////////////

export prototype Replace(BYREF STRING, STRING, STRING); // stringToOperateOn, find, replaceWith

////////////////////////////////

function Replace(text, find, replaceWith)
NUMBER listID, n, nResult;
STRING svString, svNew;
begin
listID = ListCreate(STRINGLIST);

StrGetTokens ( listID, text, find );

n = ListCount ( listID );

if (n > 0) then
nResult = ListGetFirstString (listID, svString);

while (nResult != END_OF_LIST)
svNew = svNew + svString + replaceWith;
nResult = ListGetNextString (listID, svString);
endwhile;

text = svNew;
endif;
end;

/////////////////////////////

Soap box:

InstallShield, when are you going to start really listening to/watching your users? Three or four years ago I was creating installations for our product. I had a terrible experience using your product. Our install person left the company 6 months ago and I'm back on maintaining our installer. I've been on it a couple weeks now and it's the same frustrating, time-consuming experience! Whatever your usability department is now, it needs to double in size, unless it's currently zero, in which case you need to get busy creating good one. (It's not that there are not good things with your product; it's that the ratio of bad:good is seemingly much higher than almost all other software tools I use. Kudos to the well-done features)

The replace function is found in most scripting languages. And it's not like you're trying to keep InstallScript as some lower level language--you have plenty of simplified functions: MessageBox, Delay, StrFind, etc.
0 Kudos
joshstechnij
Level 10 Flexeran
Level 10 Flexeran

InstallScript provides a function named StrReplace that can be used to perform non-textsub related string replacement.

With regards to the original behavior posted, the string that contains the textsub to be replaced needs to be as Robert had mentioned:
sNewStr = "-s -a -f1\"\\Install.iss\"";

Without the double-backslash between and Install.iss, an invalid escape sequence is generated. This is equivalent to how hard-coded strings are handled by a C/C++ compiler.

One other thing to note about textsub behavior is TextSubSubstitute will remove any trailing backslashes on textsub values (in the above case, the '\' appended to sEnvVar for TEMP will be removed when TextSubSubstitute is called).
0 Kudos