# Variable Replacement in .asp file

**URL:** https://www.finalbuilder.com/forums/t/variable-replacement-in-asp-file/820
**Category:** Discussion
**Created:** [April 24, 2008, 4:17am UTC](https://www.finalbuilder.com/forums/t/variable-replacement-in-asp-file/820 "2008-04-24T04:17:32Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [April 24, 2008, 4:17am UTC](https://www.finalbuilder.com/forums/t/variable-replacement-in-asp-file/820/1 "2008-04-24T04:17:32Z")

</div>

Is there a way to replace variables within a .asp file?&nbsp; The problem I'm having is that the file starts with \<% and ends with %\> so FB tries to replace the variables, it tries to replace everything between the %.

I've been able to get this to work using Text replacement, but it seems there should be a way to use variable replacement.

thanks

---

<div class="post-metadata">

### Author: ![angus](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@angus](https://www.finalbuilder.com/forums/u/angus)
#### Post date: [April 28, 2008, 1:34am UTC](https://www.finalbuilder.com/forums/t/variable-replacement-in-asp-file/820/2 "2008-04-28T01:34:42Z")

</div>

Hi Valeri,   
  
 Thanks for your post. You’re correct that the % signs cause problems.   
  
 The best way to correct this is to escape the individual % signs as %%. Then FinalBuilder will expand these to %, and will expand any other variable references normally.   
  
 Regards,   
  
 Angus

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [April 30, 2008, 8:44am UTC](https://www.finalbuilder.com/forums/t/variable-replacement-in-asp-file/820/3 "2008-04-30T08:44:21Z")

</div>

I"m a little confused by that…i have an asp files that I only want to have 1 % sign - if I add two then the file doesn’t function.   
  
 Even with .NET - if I want to iterate through all the files to replace all the variables then this:   
 \<%@ Page Language=“C#” MasterPageFile="~/\_master/web.master" AutoEventWireup=“true” CodeFile=“auto\_schedule.aspx.cs” Inherits=“auto\_schedule” Title=“Schedule Preference” %\>   
  
 will cause problems. I can’t escape the % because then the page won’t work.   
  
 Does that make sense? What is the suggested method of variable replacement in this instance?   
  
 Thanks,   
 Valeri

---

<div class="post-metadata">

### Author: ![angus](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@angus](https://www.finalbuilder.com/forums/u/angus)
#### Post date: [May 1, 2008, 1:11am UTC](https://www.finalbuilder.com/forums/t/variable-replacement-in-asp-file/820/4 "2008-05-01T01:11:31Z")

</div>

Hi Valeri,   
  
 Thanks for the reply. If you escape the variables as %% in the Original file, then after you do the “Replace Variables” then they will all be single % signs, and any variables (ie %MyFinalBuilderVariable%) will be replaced with their values.   
  
 So you can use the file with %%s as the “before” file, and the %s as the “after” file.   
  
 Is this OK for you? Or do you need the “before” file to be valid .asp as well?   
  
 - Angus

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [May 1, 2008, 12:24pm UTC](https://www.finalbuilder.com/forums/t/variable-replacement-in-asp-file/820/5 "2008-05-01T12:24:11Z")

</div>

No.

What I"m saying is I have a .asp file with something like this:

\<%  
'create connection  
Dim objConn  
Set objConn= Server.CreateObject("ADODB.Connection")  
objConn.Open = "DSN=DSNName; UID=UserId;PWD=%password%;"   
%\>

&nbsp;

So when I try to replace %password% it tries to replace what's between the \<% and %\> because it thinks the % start variables.

Does that make sense?

I can't do:

\<%%  
'create connection  
Dim objConn  
Set objConn= Server.CreateObject("ADODB.Connection")  
objConn.Open = "DSN=DSNName; UID=UserId;PWD=%password%;"   
%%\>

Because that will neither be a valid file before OR after the variable replacement. But yes, it needs to be valid both before AND after the replacement (simply with the wrong password).

Is there a way for Final Builder to ignore the % if preceeded by a \< or follwed by a \>?

&nbsp;

---

<div class="post-metadata">

### Author: ![angus](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@angus](https://www.finalbuilder.com/forums/u/angus)
#### Post date: [May 2, 2008, 1:52am UTC](https://www.finalbuilder.com/forums/t/variable-replacement-in-asp-file/820/6 "2008-05-02T01:52:39Z")

</div>

Hi Valeri,   
  
 Thanks for clarifying. This is a tricky thing to work around, for the reasons I outlined earlier (FinalBuilder can’t tell the difference between one % sign and another without escaping.)   
  
 If you only need to replace a handful of variables then I would recommend using a different syntax and search for the values specifically.   
  
 ie   
  
 objConn.Open = “DSN=DSNName; UID=UserId;PWD=#password#;”   
  
 … then use a Text Replace action with search text “#password#” and replace text “%password%”.   
  
 You can repeat this for any other variables you’re using in your .asp file.   
  
 Will that solve the problem?   
  
 Regards,   
  
 Angus
