Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Select specific words & words beside them...
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 08 October 2003 :  21:20:27  Show Profile
Title confusing? Yea, didn't sound as good as it did in my head. Anyway, what I'm trying to achieve is to have my script search a block of text, find certain words, and select the words next to them to be put into the database. I am getting the text from an email, and my code currently looks like this:


<% @LANGUAGE=VBSCRIPT %>
<% 


Set pop3 = Server.CreateObject( "JMail.POP3" )

pop3.Connect "usr@svr.com", "pass", "mail.svr.com"

Response.Write( "You have " & pop3.count & " emails in your mailbox!<br><br>" )

if pop3.count > 0 then
Set msg = pop3.Messages.item(1) 
%>
<html>
<body>
<TABLE>
 <tr>
  <td>Subject</td>
  <td><%= msg.Subject %></td>
 </tr>
 <tr>
  <td>From</td>
  <td><%= msg.FromName %></td>
 </tr>
 <tr>
  <td>Body</td>
  <td><pre><%= msg.Body %></pre></td>
 </tr>
</TABLE>
</body>
</html>
<%

end if

pop3.Disconnect

%>

Now, the bit I want to look at is the bit in red, <%= msg.Body %>. It will contain the following text:


Your auction for "Very good book"
(auction no.
1234567) has finished. The auction passed your reserve price
and has successfully sold.

The details of the winning bid are:
AMOUNT: $3000.00
TOP BIDDER: BOOKHUNTER
EMAIL: mailto:BOOKHUNTER@HUNTERPLACE.COM
...


Now, in the above email, the bits in Green are the variables, they are different with each email. The bits in orange are the permanants, they are always the same.

What I want the code to do is go thru that email and extract all the bits in Green to my database. Now, I can handle putting values into a database alright , but I wouldn't have a clue how to extract those values from the email. I did a bit of seraching on google Select Words ASP, but I didn't get very far (well actually I didn't get anywhere!)

Anyone had any experence with this kinda stuff or know how I can solve this problem?

Cheers,
WeeVaa.

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 08 October 2003 :  21:25:17  Show Profile
Look at the vbscript functions InStr and Mid ... they should do what you need.

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 08 October 2003 :  21:35:27  Show Profile
I found this: http://www.asptutorial.info/sscript/manipulate_string.asp

Any idea how I could manipulate the string to extract the desired data tho?

Cheers,
WeeVaa.

Go to Top of Page

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 08 October 2003 :  22:13:45  Show Profile
OK, I have added this to my code:



<% BodyString=msg.Body %> 
<% response.write "Auction number placement: = "%>

<% =InStr(BodyString," no.")+3 %>
<% response.write "<br><br>Actual auction number = "%>
<% =Mid(BodyString,83,9) %>
Edited as follows:
<% BodyString=msg.Body %> 
<% response.write "Auction number placement: = "%>

<% =InStr(BodyString," no.")+5 %>
<% response.write "<br><br>Actual auction number = "%>
<% =Mid(BodyString,InStr(BodyString," no.")+5,7) %> 


Which extracts the 7 didget auction number, but there is one thing wrong. I need the number in red to be dynamic, as the text in the email won't always be the same length, so I can't just set it to 83. Fixed it by adding the bit in red to replace the static number, works a treat!

Cheers,
WeeVaa.


Edited by - eggyfarts on 08 October 2003 22:30:02
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.34 seconds. Powered By: Snitz Forums 2000 Version 3.4.07