Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript/ASP Functions 1

Status
Not open for further replies.

fergiepl

IS-IT--Management
Jan 4, 2002
4
US
I am trying to build a simple find/replace code. I can not seem to subtract with the LEFT or RIGHT or MID functions. Can someone please help with the syntax? Thank you

<%

Dim InputPhrase, FindChar, ReplaceChar, PhraseLength,

NewPhrase,PartA,PartB,founda

InputPhrase=Request.Form(&quot;Phrase&quot;)
FindChar=Request.Form(&quot;FindMe&quot;)
ReplaceChar=Request.Form(&quot;ReplaceMe&quot;)
Phraselength=len(InputPhrase)
newphrase=inputphrase

For varCounter=1 to PhraseLength
founda=InStr(NewPhrase,FindChar)
<!--PartA is the string before the found character-->
PartA = Left(newphrase,founda-1)
<!--PartB is the remaining string-->
PartB = Right(newPhrase,4)
<!--Rebuild string and trim out space before next loop-->
NewPhrase = trim(parta) &Trim(ReplaceChar)&Trim(PartB)

Next

response.write NewPhrase

%>
 
Maybe I'm missing something but why not just use the Replace method?
 
I can not use the Replace function. I must use the Functions.
 
Code:
	For varCounter=1 to PhraseLength
		founda=InStr(NewPhrase,FindChar)
		if founda <> 0 Then
			'PartA is the string before the found character
			PartA = Left(newphrase,founda-1)
			'PartB is the remaining string
			PartB = Mid(NewPhrase,founda+1) 
			'Rebuild string and trim out space before next loop
			NewPhrase = trim(parta) &Trim(ReplaceChar)&Trim(PartB)
		end if
	Next
or
Code:
	founda = InStr(1,NewPhrase,FindChar)
	while (founda <> 0)
		'PartA is the string before the found character
		PartA = Left(newphrase,founda-1)
		'PartB is the remaining string
		PartB = Mid(NewPhrase,founda+1) 
		'Rebuild string and trim out space before next loop
		NewPhrase = trim(parta) &Trim(ReplaceChar)&Trim(PartB)
		founda=InStr(founda+1,NewPhrase,FindChar)
	wend
should work
 
Thank you! It is VERY much apprecited. It worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top