Jump to content
UBot Underground

How To Delete Only The Last Name In A List That Has First and Last Name?


Recommended Posts

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 Clarke

Matthew 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

 

 

Link to post
Share on other sites

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

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 last

name from a list that has different names.

 

Example as lets' say I had a list that had all different first and last names

I 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 name

how 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 Clarke

Robert Allen

Marcus Smith

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

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

Be 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)
    }
}
  • Like 1
Link to post
Share on other sites

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

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

Link to post
Share on other sites

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

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