ง่าย 0 ข้อที่แก้แล้ว อัตราผ่าน 0%

Replace Spaces With Dashes

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

โจทย์

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.

เงื่อนไข

0 ≤ length of text ≤ 10,000

ตัวอย่าง

ตัวอย่างที่ 1
อินพุต:
text = "Hello World"

ผลลัพธ์ที่คาดหวัง:
expected = "hello-world"
อินพุต:
std::string text = "Hello World";

ผลลัพธ์ที่คาดหวัง:
std::string expected = "hello-world";
อินพุต:
string text = "Hello World";

ผลลัพธ์ที่คาดหวัง:
string expected = "hello-world";

คำอธิบาย

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

ตัวอย่างที่ 2
อินพุต:
text = "Learn  To Code"

ผลลัพธ์ที่คาดหวัง:
expected = "learn--to-code"
อินพุต:
std::string text = "Learn  To Code";

ผลลัพธ์ที่คาดหวัง:
std::string expected = "learn--to-code";
อินพุต:
string text = "Learn  To Code";

ผลลัพธ์ที่คาดหวัง:
string expected = "learn--to-code";

คำอธิบาย

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

แหล่งอ้างอิง

โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน

เรียนรู้จากคนอื่น

แนวทางจากชุมชน

ยังไม่มีวิธีทำที่เผยแพร่ ลองแก้โจทย์นี้เพื่อแชร์วิธีแรก