How to use printf with std::string

C++23 Update We now finally have std::print as a way to use std::format for output directly: #include <print> #include <string> int main() { // … std::print(“Follow this command: {}”, myString); // … } This combines the best of both approaches. Original Answer It’s compiling because printf isn’t type safe, since it uses variable arguments in … Read more

Understanding logic in CaseInsensitiveComparator

From Unicode Technical Standard: In addition, because of the vagaries of natural language, there are situations where two different Unicode characters have the same uppercase or lowercase So, it’s not enough to compare only uppercase of two characters, because they may have different uppercase and same lowercase Simple brute force check gives some results. Check … Read more

How to remove the white space at the start of the string

This is what you want: function ltrim(str) { if(!str) return str; return str.replace(/^\s+/g, ”); } Also for ordinary trim in IE8+: function trimStr(str) { if(!str) return str; return str.replace(/^\s+|\s+$/g, ”); } And for trimming the right side: function rtrim(str) { if(!str) return str; return str.replace(/\s+$/g, ”); } Or as polyfill: // for IE8 if (!String.prototype.trim) … Read more