Solved

instr problems - finding sometimes, not other times.

Posted on 2008-10-06
3
245 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
  • 2
3 Comments
 
LVL 6

Expert Comment

by:Jammer59
Comment Utility



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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to count occurrences of each item in an array.

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now