Start learning free

LESSON 72 OF 508 · STRINGS - CHALLENGES

Concat First and Last Char in Rust

Practice

Given a string s, return a new string made of two characters: the first character of s, followed by its last character.

 

Example 1:

Input: s = "hello"
Output: "ho"
Explanation: The first character is "h" and the last one is "o".

Example 2:

Input: s = "Hello World!"
Output: "H!"
Explanation: Every character counts, so the last one is the "!", not the "d". The "H" stays upper case.

Example 3:

Input: s = "ab"
Output: "ab"
Explanation: With only two characters, the first is "a" and the last is "b".

 

Constraints:

  • s has at least 2 characters.
  • s contains English letters, digits, spaces and punctuation, and doesn't start or end with a space.
STEP 1 OF 1
    Ctrl + Enter to check

    Concat First And Last Char in Rust

    Keep going with Rust500+ step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free