Remove spaces from std::string in C++

The best thing to do is to use the algorithm remove_if and isspace: remove_if(str.begin(), str.end(), isspace); Now the algorithm itself can’t change the container(only modify the values), so it actually shuffles the values around and returns a pointer to where the end now should be. So we have to call string::erase to actually modify the … Read more

Check if string contains only whitespace

Use the str.isspace() method: Return True if there are only whitespace characters in the string and there is at least one character, False otherwise. A character is whitespace if in the Unicode character database (see unicodedata), either its general category is Zs (“Separator, space”), or its bidirectional class is one of WS, B, or S. … Read more

Trim spaces from end of a NSString

Taken from this answer here: https://stackoverflow.com/a/5691567/251012 – (NSString *)stringByTrimmingTrailingCharactersInSet:(NSCharacterSet *)characterSet { NSRange rangeOfLastWantedCharacter = [self rangeOfCharacterFromSet:[characterSet invertedSet] options:NSBackwardsSearch]; if (rangeOfLastWantedCharacter.location == NSNotFound) { return @””; } return [self substringToIndex:rangeOfLastWantedCharacter.location+1]; // non-inclusive }

Add only non-whitespace changes

@Frew solution wasn’t quite what I needed, so this is the alias I made for the exact same problem: alias.addnw=!sh -c ‘git diff -U0 -w –no-color “$@” | git apply –cached –ignore-whitespace –unidiff-zero -‘ Or you can simply run: git diff -U0 -w –no-color | git apply –cached –ignore-whitespace –unidiff-zero – Update Added options -U0, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)