Đề bài
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.
Ràng buộc
0 ≤ length of text ≤ 10,000
Ví dụ
Ví dụ 1
Đầu vào:
text = "Hello World"
Kết quả mong đợi:
expected = "hello-world"
Đầu vào:
std::string text = "Hello World";
Kết quả mong đợi:
std::string expected = "hello-world";
Đầu vào:
string text = "Hello World";
Kết quả mong đợi:
string expected = "hello-world";
Giải thích
The space becomes a dash and letters are lowercased: "hello-world".
Ví dụ 2
Đầu vào:
text = "Learn To Code"
Kết quả mong đợi:
expected = "learn--to-code"
Đầu vào:
std::string text = "Learn To Code";
Kết quả mong đợi:
std::string expected = "learn--to-code";
Đầu vào:
string text = "Learn To Code";
Kết quả mong đợi:
string expected = "learn--to-code";
Giải thích
Each space becomes its own dash: "learn--to-code".
Tham khảo
Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.