?
Solved

instr problems - finding sometimes, not other times.

Posted on 2008-10-06
3
Medium Priority
?
263 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
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Suggested Courses

621 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