Tous les défis
Facile 0 résolus 0 % de réussite

Replace Spaces With Dashes

Turn spaces into dashes to make a URL-style slug.

Problème

Replace every space in text with a dash -, and convert all letters to lowercase.

Implement slugify_spaces(text).

Input

text: The text to convert.

Output

Return the converted text.

Contraintes

0 ≤ length of text ≤ 10,000

Exemples

Exemple 1
Entrée :
text = "Hello World"

Sortie attendue :
expected = "hello-world"
Entrée :
std::string text = "Hello World";

Sortie attendue :
std::string expected = "hello-world";
Entrée :
string text = "Hello World";

Sortie attendue :
string expected = "hello-world";

Explication

The space becomes a dash and letters are lowercased: "hello-world".

Exemple 2
Entrée :
text = "Learn  To Code"

Sortie attendue :
expected = "learn--to-code"
Entrée :
std::string text = "Learn  To Code";

Sortie attendue :
std::string expected = "learn--to-code";
Entrée :
string text = "Learn  To Code";

Sortie attendue :
string expected = "learn--to-code";

Explication

Each space becomes its own dash: "learn--to-code".

Références

Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.

Apprenez des autres

Solutions de la communauté

Aucune solution publiée pour l'instant. Résolvez ce défi pour partager la première.