Walter1 8 Posted September 13, 2013 Report Share Posted September 13, 2013 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. Quote Link to post Share on other sites
Gogetta 263 Posted September 13, 2013 Report Share Posted September 13, 2013 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 Quote Link to post Share on other sites
UBotBuddy 331 Posted September 13, 2013 Report Share Posted September 13, 2013 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. Quote Link to post Share on other sites
Kev 69 Posted September 13, 2013 Report Share Posted September 13, 2013 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. Quote Link to post Share on other sites
Gogetta 263 Posted September 13, 2013 Report Share Posted September 13, 2013 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 2 Quote Link to post Share on other sites
Walter1 8 Posted September 14, 2013 Author Report Share Posted September 14, 2013 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 1 Quote Link to post Share on other sites
Gogetta 263 Posted December 30, 2013 Report Share Posted December 30, 2013 Man I'm glad I found this thread! I needed this script and I didn't save it anywhere on my computer. Quote Link to post Share on other sites
clintk 2 Posted June 29, 2019 Report Share Posted June 29, 2019 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? Quote Link to post Share on other sites
clintk 2 Posted July 7, 2019 Report Share Posted July 7, 2019 Never mind, it's sorted Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.