Challenge: String Slicing and Indexing
Oppgave
Swipe to start coding
Write a function that receives a string and a character, and returns the substring found between the first and last occurrence of the specified character in the string. If the character does not appear at least twice, return an empty string.
- Find the index of the first occurrence of
charintext. - Find the index of the last occurrence of
charintext. - Extract and return the substring that lies strictly between these two indices.
- Return an empty string if
chardoes not appear at least twice intext.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 4
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Awesome!
Completion rate improved to 6.67
Challenge: String Slicing and Indexing
Sveip for å vise menyen
Oppgave
Swipe to start coding
Write a function that receives a string and a character, and returns the substring found between the first and last occurrence of the specified character in the string. If the character does not appear at least twice, return an empty string.
- Find the index of the first occurrence of
charintext. - Find the index of the last occurrence of
charintext. - Extract and return the substring that lies strictly between these two indices.
- Return an empty string if
chardoes not appear at least twice intext.
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 4
single