You have a table user_content containing text content that needs to be properly formatted.
Table: user_content
| Column Name | Type |
|---|---|
| content_id | int |
| content_text | varchar |
content_id is the unique key for this table. Each row contains a unique ID and the corresponding text content.
Write a solution to transform the text in the content_text column by applying the following rules:
- Convert the first letter of each word to uppercase and the remaining letters to lowercase
- Special handling for words containing special characters:
- For words connected with a hyphen
-, both parts should be capitalized (e.g.,top-rated→Top-Rated)
- For words connected with a hyphen
- All other formatting and spacing should remain unchanged
Return the result table that includes both the original content_text and the modified text following the above rules.
Table Schema
| Column Name | Type | Description |
|---|---|---|
content_id
PK
|
int | Unique identifier for each content row |
content_text
|
varchar | Text content to be formatted |
Input & Output
| content_id | content_text |
|---|---|
| 1 | hello world-class service |
| 2 | top-rated product review |
| 3 | user-friendly interface design |
| content_id | original_text | formatted_text |
|---|---|---|
| 1 | hello world-class service | Hello World-Class Service |
| 2 | top-rated product review | Top-Rated Product Review |
| 3 | user-friendly interface design | User-Friendly Interface Design |
Each word's first letter is capitalized, and for hyphenated words like 'world-class', both parts are capitalized as 'World-Class'.
| content_id | content_text |
|---|---|
| 4 | API documentation |
| 5 | self-service portal |
| 6 | twenty-four hour support |
| content_id | original_text | formatted_text |
|---|---|---|
| 4 | API documentation | Api Documentation |
| 5 | self-service portal | Self-Service Portal |
| 6 | twenty-four hour support | Twenty-Four Hour Support |
All text is converted to proper case with first letters capitalized. Note that 'API' becomes 'Api' as the rule converts to lowercase first, then capitalizes first letters.
Constraints
-
1 ≤ content_id ≤ 1000 -
content_textcontains only letters, spaces, and hyphens -
1 ≤ length(content_text) ≤ 500