katelynnm 1 Posted October 8, 2013 Report Share Posted October 8, 2013 (edited) I'm trying to search a table and find all instances of a string within a specific column and replace them with nothing. For instance: search Column 1 and replace all instances of the word "mile" with nothing, but keep everything else that is in the cell. How would I go about doing that? Thank you in advance. Edited October 14, 2013 by katelynnm Quote Link to post Share on other sites
HelloInsomnia 1103 Posted October 8, 2013 Report Share Posted October 8, 2013 This is some code that should help. Basically you need to loop for the total number of rows inside of the table. Then set the table cell to be the same table cell but with a replacement of the string that you want. set table cell(&data, 0, 0, "test00") set table cell(&data, 0, 1, "test01") set table cell(&data, 1, 0, "test10") set table cell(&data, 1, 1, "test11") set(#loop_row_num, 0, "Global") loop($table total rows(&data)) { set table cell(&data, #loop_row_num, 0, $replace($table cell(&data, #loop_row_num, 0), "test", "coffee")) increment(#loop_row_num) } Quote Link to post Share on other sites
UBotDev 276 Posted October 8, 2013 Report Share Posted October 8, 2013 Instead of manually looping through the table I think you'll be able to use "$table search" function, which returns the column/row in which searched string was found (However, you will need to repeat this search while function only returns first match). Once you find that row you can change the cell with "set table cell" command. 1 Quote Link to post Share on other sites
katelynnm 1 Posted October 9, 2013 Author Report Share Posted October 9, 2013 (edited) Thank you both. HelloInsomnia: I just tried what you posted and it replaces every cell with numbers that increase by one all the way down. Here is the table that I'm trying to change: http://s12.postimg.org/ikzl0vci5/one.jpg I want it to go through the middle column and remove all instances of "m run". Basically code that changes it to this: http://s22.postimg.org/d31p69sap/image.jpg Here is my ubot code thus far: create table from file("C:\\Users\\Katelynn\\Desktop\\data2.csv", &my table) set(#loop_row_num, 0, "Global") loop($table total rows(&my table)) { set table cell(&my table, #loop_row_num, 1, $replace($table cell(&my table, #loop_row_num, 0), "m run", "nothing")) increment(#loop_row_num) } save to file("C:\\Users\\Katelynn\\Desktop\\data3.csv", &my table) Edited October 9, 2013 by katelynnm Quote Link to post Share on other sites
Pete 121 Posted October 9, 2013 Report Share Posted October 9, 2013 if this is a one off update I would use a regex set(#input, $replace regular expression($read file("C:\\Users\\Katelynn\\Desktop\\data2.csv"), "((\s[m])(\srun))", $nothing), "Global")save to file(#input, "C:\\Users\\Katelynn\\Desktop\\output.csv") Quote Link to post Share on other sites
HelloInsomnia 1103 Posted October 10, 2013 Report Share Posted October 10, 2013 +1 for what Zap said but if you want to do it the way I showed above try this code instead: create table from file("C:\\Users\\Katelynn\\Desktop\\data2.csv", &my table) set(#loop_row_num, 0, "Global") loop($table total rows(&my table)) { set table cell(&my table, #loop_row_num, 1, $replace($table cell(&my table, #loop_row_num, 1), "m run", $nothing)) increment(#loop_row_num) } save to file("C:\\Users\\Katelynn\\Desktop\\data3.csv", &my table) Quote Link to post Share on other sites
LoWrIdErTJ - BotGuru 904 Posted October 10, 2013 Report Share Posted October 10, 2013 I have a tool (plugin) that i was developing for just this thing and much more. I should have it out next day or 2 as soon as i finish up the videos, and example code Quote Link to post Share on other sites
katelynnm 1 Posted October 10, 2013 Author Report Share Posted October 10, 2013 Thank you for all of the advice, everyone! HelloInsomnia - that worked perfectly! Thank you so much!! LoWrldErTJ - I'd love to see your plugin when you've finished it-it sounds awesome! Quote Link to post Share on other sites
LoWrIdErTJ - BotGuru 904 Posted October 10, 2013 Report Share Posted October 10, 2013 ill have the sales thread up here soon and videos donebut you can see the current and planned feature set athttps://www.botguru.net/ubot-studio-list-and-csv-grids-and-extended-features/ Quote Link to post Share on other sites
Bliss 194 Posted October 10, 2013 Report Share Posted October 10, 2013 You can always check out my table plugin too http://www.ubotstudio.com/forum/index.php?/topic/12583-sell-ubot-table-addon-plugin-duplicate-tables-search-tables-sort-compare-and-more/ 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.