473,657 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to extract individual word and change them into hyperlinks?

17 New Member
Hi,all.
I want to extract all words ( not including punctuations) from a text and convert all individual words into hyperlinks directing a dictionary site. When clicking on any word will go to the dict site. How to write the javascript?
For example:
"This is a text for extraction."
The dictionary site is http://www.dic.com/
The html should be like:
This is a text for extraction.
The embedded links should be : http://www.dic.com/This
http://www.dic.com/is
http://www.dic.com/a
http://www.dic.com/text
...
Thank you very much in advance.
Oct 27 '07 #1
5 1618
gits
5,390 Recognized Expert Moderator Expert
hi ...

let me give you an idea:

Expand|Select|Wrap|Line Numbers
  1. // we declare an empty string that we use as a new html-block
  2. // later on
  3. var new_html = '';
  4.  
  5. // your text-value that you have from wherever
  6. var text = 'This is a text for extraction.';
  7.  
  8. // now we create a list from the sentence with a regEx
  9. // and leave the punctuations
  10. var words = text.match(/(\w[^ ,.!?]+)/g);
  11.  
  12. // we create the new html block here
  13. for (var i = 0; i < words.length; i++) {
  14.     var word = words[i];
  15.  
  16.     new_html += '<a href="http://www.dic.com/' + word + '">' + word + '</a>';
  17. }
  18.  
  19. // alert the new html block code
  20. alert(new_html);
  21.  
have a look at the comments, now you simply have to add new_html wherever you want ... use innerHTML for that ...

kind regards
Oct 27 '07 #2
1965
17 New Member
gits. You are great.

Thank you very much for your kind and detailed answer. Your answer should be awarded 5 stars though I have not tested it.
Oct 27 '07 #3
gits
5,390 Recognized Expert Moderator Expert
hi :)

lets have a look whether it works for you ... post back anytime in case have problems with it ...

kind regards
Oct 27 '07 #4
1965
17 New Member
Gits:

It partially works.

There is a text including "(" and "--", and"." and "," and "..." and "$"

For example
"RAMADI, Iraq (AP) -- The women received their first paychecks a few weeks ago - about $500 for a month's work as police officers. They paid rent, bought food, wiped out debts. But the seemingly simple transaction has left at least one woman in fear for her life, another threatened with divorce...."

Your script parsed it as:
"RAMADI Iraq AP) The women received their first paychecks few weeks ago about 500 for month's work as police officers They paid rent bought food wiped out debts But the seemingly simple transaction has left at least one woman in fear for her life another threatened with divorce "

Why?
Please help.
Oct 27 '07 #5
gits
5,390 Recognized Expert Moderator Expert
hi ...

it was a simple example :) ... have a look at the regEx ... it simply matches all regular characters ... and we leave ' ' and '.' and etc. for sure ... so you may adapt the regEx to your needs ...

kind regrads
Oct 27 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
3949
by: Colleyville Alan | last post by:
I have an application that has an Access table that stores the locations of slides in a Powerpoint file. This used to work fine when there were about 4 files and 200 slides. The database would open all four PPT files at once, and would loop through queriers for ever client and create custom presentations. Now there are 8 files, nearly 500 slides and the computer is bogging down with trying to open them all at once. I know that Access...
3
2394
by: David | last post by:
Hello, hope someone can help. I have a request to print word .doc check lists with selected records in Access for surgery procedure cards. I have hyperlinked the word doc's to a field in each record, but do not know how to write the code to open the word doc and print it. I assume this code should be put in the list box print button. As you can see, I have two different reports that go out; one (or more) to Surgery, and one (or more) to...
0
322
by: bjbounce2002 | last post by:
Using Access 97, I have a table containing names of and hyperlinks to Word documents. The documents are in various server directories. I would like to set up a field of type OLE Object which contains the text of each Word doc. If the Word doc changes content, I can go into Edit, OLE/DDE Links to update the link. Is there a way to update all the links of the table in one go (say when the database is opened)? There are several hundred...
3
30775
by: Adam Faulkner via DotNetMonster.com | last post by:
I want to create a method within a class that opens a Microsoft Word 2000 Document and has the facility to Create a new word document and then extract a Page that exists within the original Word Document and save it to a new Word Document. I would need to generate a loop for each page found within a word document to create a new word document and insert the existing page into the new word document and then save as a new word document. ...
1
6885
by: kidkurious | last post by:
I have a script that will read web file, extract the hyperlinks and sort them in alphabetical order. It works fine, but not the way I want. I want to change the script so that it will extract the text link as well. //sortlinks.php <?php $matches= array();
5
2611
by: Jim Carlock | last post by:
I'm looking to use an image of letters and numbers, whereby I need a way to extract each letter and number to create random strings, then combine/conjoin/meld/mesh/merge/unify/unite the images into one one image. Is it better to extract each individual letter from one image and then create the new image or is it better to use 36 different images of different names and then create the image from that? And can anyone provide any help in...
7
25781
by: Anat | last post by:
Hi, What regex do I need to split a string, using javascript's split method, into words-array? Splitting accroding to whitespaces only is not enough, I need to split according to whitespace, comma, hyphen, etc... Is there a regex that does the trick? Thanks, Anat.
0
2040
by: napolpie | last post by:
DISCUSSION IN USER nappie writes: Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file. This file is long file and it's composed by word and number arguments like this: GRILLE EURAT5 Coin Nord-Ouest : 46.50/ 0.50 Coin Sud-E Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file.
1
3801
by: vidhya17 | last post by:
I find that hyperlinks created and active in Microsoft Word are still looking like hyperlinks, but no longer active. That is to say when the Adobe Reader grasping hand mouse-pointer is over the link in the PDF version of the document it doesn't change to a pointing finger, and clicking on the link has no effect. I know it's possible to have active links in PDF documents. Question is: how is it done? Anyone able to help?
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.