Forum Moderators: open

Message Too Old, No Replies

how to replace certain characters in a include file

         

lindajames

4:10 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



hi everyone,

i have a .inc that i include into my asp pages. however, i need to know how i can find all the £ signs and replace them with $ signs before including the file into the asp page.

any suggestions would be very much appreciated.

cheers

txbakers

4:11 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is this something you want to do dynamically? If a person is in the US they should see $ and in the UK should see the pound sign?

lindajames

4:15 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



no, i just want to replace all the £ signs to $ signs as the content in the include file is fetched and stored in £ sign but i want to change it to $

txbakers

4:24 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



so you want to do it at run time, rather than change the file once and totally.

lindajames

4:26 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



well it will be better to change the file totally but the problem is that the file updates daily, so if update it once the old £ sign will come back the following day. so i think its better to change it on run time

Birdman

4:34 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm with you txbakers, do it manually(once) rather than forcing the server to do it every time.

To do it on the fly, you will need the .inc file's contents in a variable. Then you can use the replace() function.

var=replace(var,"replace-this","with-this")

I'm more a PHP guy, so forgive me if I'm off base here.

lindajames

4:42 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



how would i store the .inc file's contents in a variable

Birdman

4:48 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dim MyFile

MyFile = Request("SomeFileName")

MyFile = replace(MyFile,"This","That")

Response.Write MyFile

Give that a go.

lindajames

5:06 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



i've got it to work. but dont know if the code is correct, so if you can verify it i would be very a greatful

<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("test.txt"), 1)

do while f.AtEndOfStream = false
Response.Write replace((f.ReadLine),"£","$")
Response.Write vbCrLf
loop

f.Close
Set f=Nothing
Set fs=Nothing

%>