Jump to content
UBot Underground

replacing words from text loading from file


Recommended Posts

hi guys

 

so sorry about the bad title -

 

what im doing is loading a article into a bot then searching the text for a certain word - if the word is there then it should replace with xxx

 

xx being a anchor text -

 

so heres the problem - on many occasions i have noticed that the word being searched for is used many times in the text and when it replaces it to a anchor text it will replace all instances of that word - which isnt what im after -

 

what I would like is to replace upto 3 words with the anchor text and if more exist then leave them alone -

 

I have attached a image below showing how I am currently doing it

 

thanks

 

wow the file is too large to attach - please view it here

 

http://ubotstudio.com/forum/index.php?app=core&module=attach&section=attach&attach_rel_module=post&attach_id=1851

Link to post
Share on other sites

If the word your searching for and word your replacing are the same then that will happen and it keeps replacing the first keyword.

 

I think the regex would get a bit more complex if you are searching for and replacing same keyword as would make a loop inside the javascript to handle the replacements instead of making the loop in ubot.

Link to post
Share on other sites

Just had a little think about this and you can put a statement is so if search word and replace word are the same do a find and replace to change all instances of the keyword to a paceholder. then run it through my loops, then afterward find and replace the placeholder back to the original keyword. All should work fine then.

Link to post
Share on other sites

here you go. Will probably need some tidying up but worked when i tested it.

 

Hi - Thank alot - For some reason when i try to download it says that the attachment was not found

 

Maybe when the servers were unstable yesterday some attachments were lost

 

thanks

Link to post
Share on other sites

It works, look for yourself - http://www.screencast-o-matic.com/watch/cXVXh1XSJ

 

Not sure if you read my other posts but if you are searching for the same word as you are replacing it will only do one. This is simple to fix, just add a little extra logic.

 

I just did this as a proof of concept. I don't know exactly the purpose the OP needs this for so didn't want to waste too much time on it.

Link to post
Share on other sites

wow - i think i will need to take out some time - have a cup of coffee while looking over the code - thanks alot Guirilla will certainly try to put it to use

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...