Tất cả thử thách
Dễ 0 đã giải Tỷ lệ chấp nhận 0%

Replace Spaces With Dashes

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

Đề 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.

Học hỏi từ người khác

Giải pháp cộng đồng

Chưa có giải pháp nào được chia sẻ. Hãy giải thử thách này để đăng giải pháp đầu tiên.