Solved

instr problems - finding sometimes, not other times.

Posted on 2008-10-06
3
250 Views
Last Modified: 2011-08-18
Hi Experts,

I am using ASP classics instr to find a sting withing a long string:

The Long String:
<p>Hi there <session>FirstName</session>,</p><p>We recently received a request to add this email address <querystring>EmailAddress</querystring> to hopefully your <field1>LocalURLshort</field1> account.</p><p>If this was you, please click this link to verify the email belongs to you:</p><p> <field>VerifyLink</field> </p><p>If for some reason someone has put your email in by mistake, please ignore this email, sorry for bothering you.</p><p>If this has happened a few times, then report this person to us by clicking this link:</p><p> <field>ChangedName</field> </p><p>We will ensure they cant do it again.</p><p>Thanks for your support.</p><p>GigTxt Email System</p><p><field1>LocalURL</field1></p><p><field1>GigTxtSignature</field1></p>

The Needle
As you can see I do a search and replace for "<field>something</field>" and "<field1>something</field1>"
My issue is this:
I can't seem to get the instr to work the second time around on "<field>something</field>"
I have tried:
Changing the contents between the <field></field>
Putting it with <field1></field1> = this works, but I need to separate them?
changing the field name in the long string from: function, funct, fnc, field1 to finally field

Any ideas would be greatly appreciated, I am at a total loss as to why this is happening on this field in particular??

C
Function PersonliseBody(strContentName, strParam1, strParam2, strParam3, strParam4, strParam5, strParam6, strParam7, strParam8, strParam9, strParam10)
'Personlise Email/Site Content for User
 
dim strFieldRep, strEmailBody, strEmailBody1, i , k
 
strEmailBody = GetSiteContent(strContentName)
 
'response.write "FirstBody:" & strEmailBody & "<br>" & "<br>" & vbcrlf
if strEmailBody <> "" then
	
		'Test FNC Again
	i = 1
	do until i = instrRev(strEmailBody, "</field>") + 1
		
		strFieldRep =  Mid2("field", strEmailBody, i)
 
		'response.write "strFieldRep: " &  strFieldRep & "<br>" & vbcrlf
		strEmailBody1 = "field" & i
		response.write "field " & strEmailBody1 & "<br>" & vbcrlf
		strFieldRep = "<field>" & strFieldRep & "</field>"
		strEmailBody = replace(strEmailBody, strFieldRep,strEmailBody1)
		
		i = instr(i, strEmailBody, "</field>") + 1
	Loop
	
	'Look for Field1s to Search DB to replace
	i = 1
	do until i = instrRev(strEmailBody, "</field1>") + 1
		
		strFieldRep =  Mid2("field1", strEmailBody, i)
 
		'response.write "strFieldRep: " &  strFieldRep & "<br>" & vbcrlf
		strEmailBody1 = GetSiteContent(strFieldRep)
		response.write "field1 " & strEmailBody1 & "<br>" & vbcrlf
		strFieldRep = "<field1>" & strFieldRep & "</field1>"
		strEmailBody = replace(strEmailBody, strFieldRep,strEmailBody1)
		
		i = instr(i, strEmailBody, "</field1>") + 1
	Loop
	
	'Look for Fields to use QueryStrings
	i = 1
	k = 1
	'response.write "querystringrevpos:" &  instrRev(strEmailBody, "</querystring>") 
	
	do until i = instrRev(strEmailBody, "</querystring>") +1
		
			strFieldRep = Mid2("querystring", strEmailBody, i)
			
			response.write "Query " & Eval("strParam" &  k)	& "<br>" & vbcrlf
			strEmailBody1 = Eval("strParam" & k)
			strFieldRep = "<querystring>" & strFieldRep & "</querystring>"
			strEmailBody = replace(strEmailBody,  strFieldRep , strEmailBody1)
		
		i = instr(i, strEmailBody, "</querystring>") +1
		k = k + 1
	Loop
	
 
 
	'Look for Fields to Use Functions to Replace
'	i = 1
'	do until i = instrRev(strEmailBody, "</fnc>") + 1
'		
'		strFieldRep = Mid2("fnc", strEmailBody, i)
'		
'		strEmailBody1 = "fnc" & i
'		'if strFieldRep = "BlockLink" then
'			'strEmailBody1 = BlockLink(session("OwnerID") , strParam2 )
'		'elseif strFieldRep = "VerifyLink" then
'		'	strEmailBody1 = VerifyLink(session("OwnerID") , strParam2 )
'		'end if
'		
'		response.write "fnc:" & strEmailBody1 & "<br>"
'		strFieldRep = "<fnc>" & strFieldRep & "</fnc>"
'		strEmailBody = replace(strEmailBody, strFieldRep,strEmailBody1)
'		
'		i = instr(i, strEmailBody, "</fnc>") + 1
'	Loop
 
 
	'Look for Fields to use Session Variables to Replace
	i = 1
	do until i = instrRev(strEmailBody, "</session>") + 1
		
		strFieldRep = Mid2("session", strEmailBody,i )
										
		strEmailBody1 = session(strFieldRep)
		response.write "session:" & strEmailBody1 & "<br>"
		response.write "sessionFN:" & session("FirstName") & "<br>"
		strFieldRep = "<session>" & strFieldRep & "</session>"
		strEmailBody = replace(strEmailBody, strFieldRep, strEmailBody1)
		
		i = instr(i, strEmailBody, "</session>") + 1
	Loop
end if
 
'response.write "<br><br>test output<br>" & vbcrlf
'response.write strEmailBody & vbcrlf
PersonliseBody = strEmailBody & vbcrlf
End Function

Open in new window

0
Comment
Question by:Craig Lambie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Expert Comment

by:Jammer59
ID: 22659162



Your function appears to be calling additional functions mid2 and instrRev which you did not post the code for.  Could you post the code for these routines?

I am actually unclear about what you are trying to accomplish.  Could you be more specific.  I see the long string input.  
Could you provide:  
     (1)   what you would like the output to look like
     (2) what the variables are and where they come from which are used to build the
           output.  For example, the FirstName variable comes from the session.  The
           emailAddress comes from the querystring, etc.
 
 
0
 
LVL 1

Author Comment

by:Craig Lambie
ID: 22664124
Hi,

instrRev is a standard ASP function that is just instr, but looks from the end instead of the start
mid2 does exactly what Mid does, but mid was causing all sorts of issues, as per
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_23789358.html

1.
The output will look like ( removing the <field> etc and replacing with a string)
The Long String:
<p>Hi there FirstName,</p><p>We recently received a request to add this email address Email@test.com to hopefully your LocalURL account.</p><p>If this was you, please click this link to verify the email belongs to you:</p><p> VerifyLink </p><p>If for some reason someone has put your email in by mistake, please ignore this email, sorry for bothering you.</p><p>If this has happened a few times, then report this person to us by clicking this link:</p><p> ChangedName </p><p>We will ensure they cant do it again.</p><p>Thanks for your support.</p><p>GigTxt Email System</p><p>LocalURL</p><p>GigTxtSignature</p>
2.
The varialbles are
<field> - gotten by running a function in long term, but just using a simple string in this case
<field1> - looks up a value in the Db
<session> - a session variable (ie. inside the tags is the name of the session variable)
<querystring> - as I converted this to a function, it is now a Parameter of the function

Problem Variables are
VerifyLink
ChangedName (was BlockLink)

These are <field> type at the moment.  I have tried <funct>, <fnc>, <test>, <field1> and now <field>


Function Mid2(strFind, strInput, j)
 
	Mid2 = right(strInput, len(strInput) - instr(j, strInput, "<" & strFind & ">")-len(strFind)-1)
	Mid2 = left(Mid2, instr(1, Mid2, "</" & strFind & ">")-1)
	
	response.write "<br>Mid2:" & j & " :" & Mid2 & "<br>" & vbcrlf
 
End Function

Open in new window

0
 
LVL 1

Accepted Solution

by:
Craig Lambie earned 0 total points
ID: 22664770
I fixed it ! Somehow?

Line 23 is now
      i = instr(i, strEmailBody, "<field>") + 1

And that appears to make it work?
No idea why/ how.  As it is different from all the others.







































































































































0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question