Logo

Programming-Idioms

Create the string t consisting of the string s without its leading and trailing whitespace characters.
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
#include <string>
using namespace std;
string t {s};
int n (t.length()), x {}, y {n - 1};
while (x not_eq  n && isspace(t[x])) ++x;
while (y not_eq -1 && isspace(t[y])) --y;
t = t.substr(x, (y - x) + 1);
import "strings"
t := strings.TrimSpace(s)
let t = s.trim()
String t = s.trim();
String t = s.strip();
t = s.strip()
from string import whitespace
t = s.strip(whitespace)
t = s.strip