02-27-2003, 11:18 AM
If the paragraph coming from the database looks like the following:
Mails can be sent to the following address firstname.lastname@example.org. Visit the site for the latest news at www.xyz.com.
For the best information on what’s going on around visit http://www.xyz.com. For enquires mail at email@example.com and so on..
How is it possible to recognize all the email address and links from the above and display them as – mailId@abc.com (<a href = mailto:mailId@abc>firstname.lastname@example.org</a>) and links as http://www.xyz.com.
02-27-2003, 03:43 PM
My first guess would be to do a InStr(@) to find the emails "@" or urls "http://". When you find a "@" in your paragraph you will have to do some more string manipulation. For emails you will have to use InStrRev("your paragraph"," ",InStr("@")) and find a " " for the beginning of your email. You then can do a InStr(InStr(@),"paragraph"," "). These will return numeric postions of the email address with these values do a Mid() to return this section (or email address). Finally do a Replace(). You may want to check to make sure it is somewhat of a valid email before you set the link too. This is based that there can not be " " in a email address. These same functions can be used to detect a url. One more note is that InStr() or InStrRev() finds the first occurence of the string you are searching for. What this means is that when you are searching for a "@" be sure to set the start postion of the last @ found.
I hope this helps and not confuse.
vbscript functions (http://www.devguru.com/Technologies/vbscript/quickref/functions.html)
what allida77 said + check for a dot (".") and chack if the possition of the dot is higher then the position of the @
of coarse. this isn't bulletproof.
if i relly need to be sure. I just ask them to fill in an email adress and then mail something to then (pasword, registration key, ...) and require them to get back to my site an type in the key or stuff
but even then ....
the email-account can be closed down the next day etc etc.
03-01-2003, 02:57 AM
In order to do this right, you need to parse all of the links out using regular expression matches.
Usually Allida77 and raf are absolutely correct when they post solutions - but in this case, using typical string manipulation is taking the wrong path, and won't accomplish what you're trying to do at all, unless you want to use dozens of lines of code where perhaps one line would be appropriate. (No offense intended to raf or Allida77... regular expressions are not as well known as they should be!).
Are you familiar with regex's? It looks like your example will require a few precise ones, so you might want to look up regular expression examples for parsing links on http://www.google.com, etc., although I can help you out with them somewhat, perhaps, as we have some good regex's at work (some of which I helped devise) for at least <a href=""> type links, and www.whatever.com type links, etc.
You might also want to do a search of the forums, since many _very_ good regular expressions have been posted that do exactly this type of pattern matching.
Once you figure regular expressions out, they are much more precise than any other string manipulation technique. Using InStr() is just ghastly in this case...
03-03-2003, 05:45 AM
Thanks to all of you for replying.
I am not familiar with regex's. I would appreciate if you could help me. I need to recognise mail ids and urls.
As suggested by you i will search for regular expression examples for parsing links.
ok whammy :o i stand corrected. Maybe i'll start a self-help group
i'll look into regex's. (Maybe, that is, since they only say the email or url is "well formed" and not that they actually exist. I alway try to avoid using email communication in my app's and they are never vital + if a user inserts a non-existing email, this should only have negative effects for him)
For external url's: the same + add a disclaimer or a message box that say you're now leaving the app's site and that you can't secure that the link points to an existing page etc etc
03-03-2003, 03:32 PM
I will have to join Raf's self help group. I actually like doing string manipulations so since I dont know regexs my first instinct is to always use all the string manipulation functions. I actually tried to do this at home to see how many lines I could do it in. In a perfect world where users type in emails and http://s properly it is really not a problem but since that world doesnt exist the code gets kind of flaky. Regexs have always been on the list of things to learn but I just have never done it.
03-03-2003, 04:41 PM
That link will give you quite a few to play around with...
Some good resources:
Believe me, they are REALLY useful... I have some you can look at here that are mostly pretty simple: