mrwalt 34 Posted March 13, 2014 Report Share Posted March 13, 2014 Hey Fellow Ubotters, Question - I would be honored if one of you lend your assistance on this question. Let's you have collected a list of people and that list contains only first and last name (as you scraped this data from a website) but you only would like to keep the first name and delete the last name from the list how would you go about doing this. I'm not that well versed in Regex so I know that this will probably be the one time that I need to use it. However the list of name is like this below with a space in the middle between the first and last name. Susan ClarkeMatthew Jacobs I'm just curious if you already have the first and last name in a list how would you be able to delete only the last name? I would greatly appreciate your feedback and advice on how you would go about dealing with this. Thank you, mrwalt Quote Link to post Share on other sites
pash 504 Posted March 13, 2014 Report Share Posted March 13, 2014 Sample remove first and remove end add item to list(%a, "a", "Delete", "Global") add item to list(%a, "b", "Delete", "Global") add item to list(%a, "c", "Delete", "Global") pause script remove from list(%a, 0) pause script remove from list(%a, $subtract($list total(%a), 1)) Quote Link to post Share on other sites
mrwalt 34 Posted March 13, 2014 Author Report Share Posted March 13, 2014 Hi Pash, I thank you for the example and I'm glad for your time but maybe I'm missing something as I don't see how this can remove the lastname from a list that has different names. Example as lets' say I had a list that had all different first and last namesI unfortunately don't understand how the below code would work. Let's say all the names below have a space in between the first and last namehow would we be able to remove this with the code below? So we have already scraped these names to 1 list within Ubot so how would we delete the last names from this list? Mary ClarkeRobert AllenMarcus SmithJoyce Anderson Again I really the help but just trying to understand. mrwalt Sample remove first and remove end add item to list(%a, "a", "Delete", "Global") add item to list(%a, "b", "Delete", "Global") add item to list(%a, "c", "Delete", "Global") pause script remove from list(%a, 0) pause script remove from list(%a, $subtract($list total(%a), 1)) Quote Link to post Share on other sites
mrwalt 34 Posted March 13, 2014 Author Report Share Posted March 13, 2014 Does anyone have any other suggestion about how you may do this with or without Regex? I would greatly appreciate your feedback. Quote Link to post Share on other sites
giganut 109 Posted March 13, 2014 Report Share Posted March 13, 2014 Well this one really put my brain to work! This may not be the best method of doing this, but it works.I have only tested this with four lines. Let me know if the code stay synced up with large lists. AlsoBe sure there is a space set as the delimiter in the add item to list >> List from text >> delimiter clear list(%FirstAndLast1) clear list(%FirstAndLast2) add item to list(%FirstAndLast1, $list from text("Mary Clarke Robert Allen Marcus Smith Joyce Anderson", " "), "Delete", "Global") add list to list(%FirstAndLast2, $list from text(%FirstAndLast1, $new line), "Delete", "Global") set(#BreakLoop, 0, "Global") set(#Remove, 1, "Global") set(#InfiniteLooper, 0, "Global") loop while($comparison(#InfiniteLooper, "=", 0)) { remove from list(%FirstAndLast2, #Remove) increment(#BreakLoop) wait(1) if($comparison($list total(%FirstAndLast2), "=", #BreakLoop)) { then { set(#InfiniteLooper, 1, "Global") } } loop(1) { increment(#Remove) } } 1 Quote Link to post Share on other sites
giganut 109 Posted March 13, 2014 Report Share Posted March 13, 2014 I just tested the code with 100 first and last names and all seems to be well, here is the code again with more names added. clear list(%FirstAndLast1) clear list(%FirstAndLast2) add item to list(%FirstAndLast1, $list from text("Lavette Origer Ezekiel Carlton Sol Gaetke Abel Burington Pei Katzmann Danilo Laun Rosalee Tanenbaum Royce Polakowski Nydia Magro Joshua Usher Rosella Segur Mose Sprenger Aleen Pachero Lee Leverson Deirdre Pribyl Isiah Dishong Julienne Viniard Gale Berges Hope Pitorak Bud Harthcock Sam Hsiang Aubrey Filippone Lila Paradise Ezekiel Tillinghast Rosalie Helder Carson Bortle Jeneva Bongartz Nicky Sharr Rutha Holmstrom Angel Muscat Eboni Gardunio Clint Cyran Bettina Wickline Ervin Bauman Myrtle Cui Dorsey Pinheiro Refugia Antillon Marcelo Fonger Cary Lethco Erik Riendeau Janna Locante Keven Tietz Katharine Curt Edmund Bukovac Janis Domenick Hassan Snith Bailey Sower Bert Douma Carmen Zolty Scottie Chiarello Valencia Vanhampler Trevor Thebo Clemmie Bengston Taylor Gallego Jesica Derosa Michale Santone Emely Paulo Mckinley Hockema Yasmin Felde Jody Reckner Dorthea Lingardo Douglass Malatesta Janey Degan Tyrone Deel Corrine Ditore Donnie Blye Holly Haake Buddy Villasana Nyla Seigler Douglass Palanza Jacinda Keiger Ike Liang Lois Stake Dave Rydeen Rena Burian Bobby Keehne Kortney Nuckles Mohammed Kukauskas Marissa Reschke Hans Termeer Terrie Fecat Cornell Belrose Tarsha Turrentine Ernesto Skill Audria Leddon Coleman Suter Deeann Bradstreet Martin Gavitt Susie Bischel Leslie Prokup Minna Marth Franklin Pangilinan Ellena Iha Jc Burston Laureen Sparr Winford Neira Iesha Pardall Pat Governale Arlette Carbonneau Marcellus Merk", " "), "Delete", "Global") add list to list(%FirstAndLast2, $list from text(%FirstAndLast1, $new line), "Delete", "Global") set(#BreakLoop, 0, "Global") set(#Remove, 1, "Global") set(#InfiniteLooper, 0, "Global") loop while($comparison(#InfiniteLooper, "=", 0)) { remove from list(%FirstAndLast2, #Remove) increment(#BreakLoop) wait(1) if($comparison($list total(%FirstAndLast2), "=", #BreakLoop)) { then { set(#InfiniteLooper, 1, "Global") } } loop(1) { increment(#Remove) } } Quote Link to post Share on other sites
UBotBuddy 331 Posted March 13, 2014 Report Share Posted March 13, 2014 Or what about this? set(#data, "Bob Newhart Carol Burnett Jim Nabors Barack Obama George Bush", "Global") clear list(%NameList) add list to list(%NameList, $list from text(#data, " "), "Delete", "Global") loop($list total(%NameList)) { set(#data, $next list item(%NameList), "Global") set(#data, $replace regular expression(#data, "^(.\{1,\}) .\{1,\}", "$1"), "Global") set(#position, $subtract($list position(%NameList), 1), "Global") remove from list(%NameList, #position) add item to list(%NameList, #data, "Delete", "Global") } Goodluck! Buddy Quote Link to post Share on other sites
mrwalt 34 Posted March 13, 2014 Author Report Share Posted March 13, 2014 I thank both of you for your input on this and I will try them both. Buddy I need to enlist in your training after this as a way to say thank you. Thank you both. mrwalt Quote Link to post Share on other sites
UBotBuddy 331 Posted March 13, 2014 Report Share Posted March 13, 2014 Cool! Come on in. The waters great! Buddy 1 Quote Link to post Share on other sites
giganut 109 Posted March 13, 2014 Report Share Posted March 13, 2014 Your welcome. BTW in my code you can remove the wait and it will be much faster. Quote Link to post Share on other sites
mrwalt 34 Posted March 14, 2014 Author Report Share Posted March 14, 2014 I tested both and they are both good. Again thank you both for your feedback.and support. 1 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.