Jump to content
UBot Underground

Replace one word instead of all.


Recommended Posts

Hey guys,

 

 

Got a question wich is bothering me for a long time and since i can't find any answer ill post it here.

 

Say i want to replace a certain keyword in a article for another i can use the $replace function.

Thing is, all the existing keywords will be replaced, but i just want one or two replacements.

 

Ill bet there is a solution but im loosing too much sleep about this one hahaha....

 

 

Thanks in advance.

 

 

Link to post
Share on other sites

Edit: I came up with a solution where this can be done randomly...

 

http://www.ubotstudio.com/forum/index.php?/topic/14882-replace-one-word-instead-of-all/?p=83882

 

 

There is a very good post by UBotDev where he explains how this can be done.

 

http://www.ubotstudio.com/forum/index.php?/topic/14402-regex-match-and-replace-x-occurrence/&do=findComment&comment=80307

Link to post
Share on other sites

There is MUCH more to it than just using the $Replace.  Quite literally, you need to break down the entire text into smaller subsets THEN do the replace and then reconstruct the text from the smaller subsets.  that link is a great description of what needs to be done.

 

Unfortunately, there is not an easy quick way of doing this.  Not even from a Regex perspective.

 

I would love to see a formula whereby you could skip around an replace randomly, 1, 2 or x times without doing ALL of them.

Link to post
Share on other sites

Just thinking this out loud so it may not work.

 

Scrape the entire text and add it to a list called %replacetext, so you have a list of items dozens of items long (assuming large page of text).

 

Next, set list position to zero.

 

Loop list total of %replacetext.

 

Set some variable, lets call it #sentence, set it as next list item using %replacetext as the list.

 

If #sentence contains (word you want to replace) then $replace and then stop script.

 

So, it should replace whatever word you want replaced as long as it is found in just that list position.

 

However, if that word appears twice on that list item it would be replaced twice. Might not be that big of a problem though.

Link to post
Share on other sites

Here you go this should work and it is random. Just set the amount of times you want the word to be replaced.

 

Edit: I fixed this script. I changed the %piece_text from delete duplicates to don't delete duplicates so the set number of occurrences will always be replaced. This script can be used to inject links, images, videos, etc.

 

Tip: Try setting the match word as a single space. That way the links or whatever will be replaced between random words throughout the article.

replace occurrences.ubot

  • Like 2
Link to post
Share on other sites

Fellow botters,

 

Thanks for all your great input on this problem, thats why i love this forum so much. Nobody is too big to help one and each other.

 

The code Gogetta placed here just works like a charm and i would like to thank you for that man. Really awesome!

 

It just shows that working with lists is much more then just to store data. And i REALLY need to learn regex...

 

 

I am learning every day here ;)

  • Like 1
Link to post
Share on other sites
  • 3 months later...
  • 5 years later...

Here you go this should work and it is random. Just set the amount of times you want the word to be replaced.

 

Edit: I fixed this script. I changed the %piece_text from delete duplicates to don't delete duplicates so the set number of occurrences will always be replaced. This script can be used to inject links, images, videos, etc.

 

Tip: Try setting the match word as a single space. That way the links or whatever will be replaced between random words throughout the article.

I am using this to learn with but it adds the replaced word at the end of the content and I cannot see why it is doing that, Are you able to help please Gogetta?

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...