Trim leading white space with PHP?

Strip all whitespace from the left end of the title: <?php echo ltrim(wp_title(”)); ?> Strip all whitespace from either end: <?php echo trim(wp_title(”)); ?> Strip all spaces from the left end of the title: <?php echo ltrim(wp_title(”), ‘ ‘); ?> Remove the first space, even if it’s not the first character: <?php echo str_replace(‘ ‘, … Read more

Regex that matches anything except for all whitespace

This looks for at least one non whitespace character. /\S/.test(” “); // false /\S/.test(” “); // false /\S/.test(“”); // false /\S/.test(“foo”); // true /\S/.test(“foo bar”); // true /\S/.test(“foo “); // true /\S/.test(” foo”); // true /\S/.test(” foo “); // true I guess I’m assuming that an empty string should be consider whitespace only. If an … Read more

How to trim whitespace between characters

You could use String.Replace method string str = “C Sharp”; str = str.Replace(” “, “”); or if you want to remove all whitespace characters (space, tabs, line breaks…) string str = “C Sharp”; str = Regex.Replace(str, @”\s”, “”);

whitespace in the format string (scanf)

Whitespace in the format string matches 0 or more whitespace characters in the input. So “%d c %d” expects number, then any amount of whitespace characters, then character c, then any amount of whitespace characters and another number at the end. “%dc%d” expects number, c, number. Also note, that if you use * in the … Read more