So, I'm helping out someone, and I'm trying to extract only the name of the cancer in the column, without including "Deaths -".
In Column A, the entries all have this pattern, each string below being in it's own separate row...
Deaths - Prostate cancer - Sex: Both - Age: Age-standardized (Rate)
Deaths - Breast cancer - Sex: Both - Age: Age-standardized (Rate)
Deaths - Testicular cancer - Sex: Both - Age: Age-standardized (Rate)
Deaths - Non-melanoma cancer - Sex: Both - Age: Age-standardized (Rate)
Deaths - Tracheal, bronchus, and lung cancer - Sex: Both - Age: Age-standardized (Rate)
I've been able to extract the name of the cancer, including removing the word "cancer" with this LEFT and SEARCH formula below...
=LEFT(A2, SEARCH("cancer", A2)-1)
Resulting in the following...
Deaths - Breast
Deaths - Testicular
Deaths - Non-melanoma
Deaths - Tracheal, bronchus, and lung
But, I can't seem to combine REGEXREPLACE with LEFT and SEARCH in one formula to also take out "Deaths" and the - (dash), leaving only the name of the cancer.
So, the desired result is below...
Breast
Testicular
Non-melanoma
Tracheal, bronchus, and lung
Thanks for any help you can provide.
try simple:
=INDEX(IFNA(REGEXEXTRACT(A1:A6, "- (.+) cancer")))
Related
Advanced – For Loops
Create a program that takes someone’s age, and then outputs a key event from every year they have lived through.
· Extension, allow a user to input their birthday for further accuracy
· Code efficiency, use an array for key events instead of if statements.
I have created the array consisting of years and events from 1993
So how do I create a for loop which gets a users year of birth (input) and displays the events from that year to the current year?
edYearlyEvents = {
"1993": "Bill Clinton is inaugurated as the 42nd president.",
"1994": "The People's Republic of China gets its first connection to the Internet.",
"1995": "eBay is founded by Pierre Omidyar.",
"1996": "Murder of Tupac Shakur.",
"1997": "The first episode of Pokémon airs on TV Tokyo.",
"1998": "Death of Frank Sinatra.",
"1999": "The Columbine High School massacre in Colorado, United States, causes 15 deaths.",
"2000": "The Sony PlayStation 2 releases in Japan. ",
"2001": " September 11 attacks.",
"2002": "The 2002-2004 SARS outbreak began in Guangdong.",
"2003": "The United States invades Iraq and ousts Saddam Hussein, triggering worldwide protests and an 8 year war",
"2004": "First surface images of Saturn's moon Titan.",
"2005": "Hurricane Katrina kills 1,836 people in the Gulf of Mexico.",
"2006": "Twitter is launched.",
"2007": "Introduction of the iPhone.",
"2008": "Barack Obama is elected to become the first black President of the United States.",
"2009": "The cryptocurrency Bitcoin is launched.",
"2010": "The Burj Khalifa in Dubai becomes the tallest structure in the world, standing at 829.8 m (2,722 ft).",
"2011": "Osama bin Laden is shot dead by United States Navy SEALs in Pakistan.",
"2012": "Vladimir Putin is elected president of Russia for the third time.",
"2013": "Terrorist attacks occur in Boston and Nairobi.",
"2014": "The worst Ebola epidemic in recorded history occurs in West Africa, infecting nearly 30,000 people and resulting in the deaths of 11,000+.",
"2015": "Liquid water is found on Mars.",
"2016": "El Chapo is recaptured following his escape from a high-security prison in Mexico",
"2017": "January 20: Donald Trump is inaugurated as President of the United States.",
"2018": "Saudi Arabia allows women to drive.",
"2019": "A major fire engulfs Notre-Dame Cathedral in Paris, resulting in the roof and main spire collapsing.",
"2020": "The murder of George Floyd sparks protests across the United States and the world.",
"2021": "Supporters of President Donald Trump, gathered after a rally led by him, attack the United States capitol, leading to five deaths.",
"2022": "Monkeypox outbreak",
"2023": "The funeral of Pope Benedict XVI is held at Saint Peter's Square within the Vatican City.",
}
sBirthYear = input("What year were you born in: \n")
for sBirthYear in dYearlyEvents.items():
print(sBirthYear)
const events = {
"1993": "Bill Clinton is inaugurated as the 42nd president.",
"1994": "The People's Republic of China gets its first connection to the Internet.",
"1995": "eBay is founded by Pierre Omidyar.",
"1996": "Murder of Tupac Shakur.",
"1997": "The first episode of Pokémon airs on TV Tokyo.",
"1998": "Death of Frank Sinatra.",
"1999": "The Columbine High School massacre in Colorado, United States, causes 15 deaths.",
"2000": "The Sony PlayStation 2 releases in Japan. ",
"2001": " September 11 attacks.",
"2002": "The 2002-2004 SARS outbreak began in Guangdong.",
"2003": "The United States invades Iraq and ousts Saddam Hussein, triggering worldwide protests and an 8 year war",
"2004": "First surface images of Saturn's moon Titan.",
"2005": "Hurricane Katrina kills 1,836 people in the Gulf of Mexico.",
"2006": "Twitter is launched.",
"2007": "Introduction of the iPhone.",
"2008": "Barack Obama is elected to become the first black President of the United States.",
"2009": "The cryptocurrency Bitcoin is launched.",
"2010": "The Burj Khalifa in Dubai becomes the tallest structure in the world, standing at 829.8 m (2,722 ft).",
"2011": "Osama bin Laden is shot dead by United States Navy SEALs in Pakistan.",
"2012": "Vladimir Putin is elected president of Russia for the third time.",
"2013": "Terrorist attacks occur in Boston and Nairobi.",
"2014": "The worst Ebola epidemic in recorded history occurs in West Africa, infecting nearly 30,000 people and resulting in the deaths of 11,000+.",
"2015": "Liquid water is found on Mars.",
"2016": "El Chapo is recaptured following his escape from a high-security prison in Mexico",
"2017": "January 20: Donald Trump is inaugurated as President of the United States.",
"2018": "Saudi Arabia allows women to drive.",
"2019": "A major fire engulfs Notre-Dame Cathedral in Paris, resulting in the roof and main spire collapsing.",
"2020": "The murder of George Floyd sparks protests across the United States and the world.",
"2021": "Supporters of President Donald Trump, gathered after a rally led by him, attack the United States capitol, leading to five deaths.",
"2022": "Monkeypox outbreak",
"2023": "The funeral of Pope Benedict XVI is held at Saint Peter's Square within the Vatican City.",
}
const yearOfBirth = 1995
const eventsBeforeMyBirth = Object.keys(events).filter(i => Number(i) <= yearOfBirth).map(i => {
return {
[i]: events[i]
}
})
console.log(eventsBeforeMyBirth)
I have a YAML document that contains an array. I would like to conditionally add properties to the elements of that array using yq version 4 from mikefarah.
Here is a sample YAML document.
name: "My Pets"
pets:
- name: "cat"
age: 8
- name: "dog"
age: 3
- name: "mouse"
age: 1
I would like to transform this into,
name: "My Pets"
pets:
- name: "cat"
age: 8
shots: cat.upToDate
- name: "dog"
age: 3
shots: dog.upToDate
- name: "mouse"
age: 1
shots: mouse.upToDate
where we add a shots property to each element of pets. The value of shots should be whatever the name value is, dot, upToDate.
I'm trying something like this,
yq eval '.pets[] | select(.name == "cat").shots = "cat.upToDate"' test.yaml
but that produces,
name: "cat"
age: 8
shots: cat.upToDate
name: "dog"
age: 3
name: "mouse"
age: 1
I need to preserve the entire original YAML document and just insert the shots property.
This is close but missing all of the other pets.
yq eval '.pets = (.pets[] | select(.name == "cat").shots = "cats.upToDate")' test.yaml
It produces,
name: "My Pets"
pets:
name: "cat"
age: 8
shots: cats.upToDate
I'm thinking maybe we could store the name of the pet in a variable and reference that later, but v4 is brand new to me today.
I would prefer to have a one-liner so that I don't have to filter on .name. This array has less than 10 elements so I could easily hard-code the name and call yq 10 times.
Any thoughts or suggestions? Many thanks, Weldon
Use |=, e.g. like so:
yq eval '.pets[] |= (.shots = (.name + ".upToDate"))' pets.yaml
I'm trying to sort teams by ranking, using AngularFire and Firebase.
In Firebase I have 4 teams where I store only the name.
I also store matches, which have a reference to both teams disputing that match and the score for each one.
The matches node looks like this:
matches
-KQgphN_5692GySN0Oxz
home_team: teamA
away_team: teamB
score
home: 1
away: 2
-KQlu6XLak6LgAr9cTty
home_team: teamC
away_team: teamD
score
home: 2
away: 2
And the teams node:
teams
teamA
name: "Team A"
teamB
name: "Team B"
teamC
name: "Team C"
teamD
name: "Team D"
So, I need to order these teams by vitories, draws and losses by watching the results in realtime.
I have a ng-repeat that lists teams like this:
<li ng-repeat="team in teams">{{team.name}}</li>
So, how can I order these teams by wins, taking in account that a win is equivalent to 3 points, a draw is 1 point and a loss is 0 points?
With the above matches example, the ranking should be:
1 - Team B
2 - Team C
3 - Team D
4 - Team A
You can order a Firebase Database query by a nested value, as long as that nested value is at a fixed path. This means you'll need to store the score for each team, e.g.
teams
teamA
name: "Team A"
score: 20
teamB
name: "Team B"
score: 12
teamC
name: "Team C"
score: 42
teamD
name: "Team D"
score: 31
With this structure, you can load the top teams in order with:
var leaders = ref.child('teams').orderByChild('score').limitToLast(3);
leaders.on('value', function(snapshot) {
leaders.forEach(function(leaderSnapshot) {
console.log(leaderSnapshot.child('name').val());
});
});
This will print:
Team A
Team D
Team C
So to get the leaderboard, you'll need to invert them.
I have a table with column "Long Description" typically the data looks like the following.
Foundation area wall, 12" H. x 20" W. x 8" projection. Galvanized. Refer to model No. SV208 (SKU 100002) for foundation area wall cover. No. FV208-12: Height: 12", Width: 20", Projection: 8", Type: Foundation Area Wall, Material: Galvanized, Pkg Qty: 1
What I am trying to do is parse out the end attributes. For example after "area wall cover." and beginning with "No." I'd like to extract the following. (Below)
Some things to note. The string '. No.' always begins the attributes in this column. All attributes are separated by columns. The attribute names differ and the amount of attributes per product also differ. Is there a way this can be done with T-SQL?
No. FV208-12:
Height: 12"
Width: 20"
Projection: 8"
Type: Foundation Area Wall
Material: Galvanized
Pkg Qty: 1
You can use a variation of the following to achieve what I believe you're attempting to achieve:
DECLARE #StartAttributesKey VARCHAR(50) = 'area wall cover. ' ,
#LongDescription VARCHAR(MAX) = 'Foundation area wall, 12" H. x 20" W. x 8" projection. Galvanized. Refer to model No. SV208 (SKU 100002) for foundation area wall cover. No. FV208-12: Height: 12", Width: 20", Projection: 8", Type: Foundation Area Wall, Material: Galvanized, Pkg Qty: 1';
SELECT REPLACE(SUBSTRING(#LongDescription, CHARINDEX(#StartAttributesKey, #LongDescription, 0) + LEN(#StartAttributesKey),
LEN(#LongDescription) - CHARINDEX(#StartAttributesKey, #LongDescription, 0)), ',', CHAR(10));
Using this in a query would be similar to:
DECLARE #StartAttributesKey VARCHAR(50) = 'area wall cover. '
SELECT REPLACE(SUBSTRING(LongDescription, CHARINDEX(#StartAttributesKey, LongDescription, 0) + LEN(#StartAttributesKey),
LEN(LongDescription) - CHARINDEX(#StartAttributesKey, LongDescription, 0)), ',', CHAR(10))
FROM [someTable] WHERE ID = 1
If you copy (or print) the result, you will see each attribute on a separate line.
I want to print data like this :
FirstName FamilyName (33 characters), Tel: xxxxxxxxxx, Age: xx, Level: xx, Salary: xxxxx.xx
For example
John Dilbert Tel: 6135202600, Age: 58, Level: 13, Salary: 450.34
Jane Smith Tel: 6135202600, Age: 47, Level: 10, Salary: 133450.00
Main problem am facing is how to put Tel: one before the other . Also how to format the floating salary such that decimal comes one below the other.
Currently my output look like this :
John Dilbert Tel: 6135202600, Age: 58, Level: 13, Salary: 450.34
Jane Smith Tel: 6135202600, Age: 47, Level: 10, Salary: 133450.00
Code :
void printData(struct person currentPerson){
printf("%s %-33sTel: %10s",currentPerson.firstName,currentPerson.familyName,currentPerson.telephone);
}
void printStudent(struct Student currentStudent){
printf("GPA:%3d, Courses:%3d, Tuition: %5f\n",currentStudent.GPA,currentStudent.coursesCount,currentStudent.tuitionFees);
}
In main:
printData(person[i]);
printf(", ");
printStudent(person[i].student);
But still result is wrong. Why ? Please help
If you want to control the width of your data, then you could use the width sub-specifiers in the printf format string. Eg. :
printf("%5d", 2);