Jump to content
UBot Underground

[solved]Find and Delete/Replace from Column


Recommended Posts

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 by katelynnm
Link to post
Share on other sites

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)
}

Link to post
Share on other sites

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.

  • Like 1
Link to post
Share on other sites

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 by katelynnm
Link to post
Share on other sites

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")
Link to post
Share on other sites

+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)

Link to post
Share on other sites

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!

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