Challenge: String Slicing and Indexing
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
Tak for dine kommentarer!
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Can you explain this in simpler terms?
What are the main takeaways from this?
Can you give me an example?
Awesome!
Completion rate improved to 6.67
Challenge: String Slicing and Indexing
Stryg for at vise menuen
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
Tak for dine kommentarer!
single