How to convert an instance of std::string to lower case

Adapted from Not So Frequently Asked Questions: You’re really not going to get away without iterating through each character. There’s no way to know whether the character is lowercase or uppercase otherwise. If you really hate tolower(), here’s a specialized ASCII-only alternative that I don’t recommend you use: Be aware that tolower() can only do a per-single-byte-character substitution, which … Read more

Multi-line string with extra space (preserved indentation)

Heredoc sounds more convenient for this purpose. It is used to send multiple commands to a command interpreter program like ex or cat The string after << indicates where to stop. To send these lines to a file, use: You could also store these lines to a variable: This stores the lines to the variable named VAR. When printing, remember the … Read more

Multiline string literal in C#

You can use the @ symbol in front of a string to form a verbatim string literal: You also do not have to escape special characters when you use this method, except for double quotes as shown in Jon Skeet’s answer.

Best way to convert an ArrayList to a string

Java 8 introduces a String.join(separator, list) method; see Vitalii Federenko’s answer. Before Java 8, using a loop to iterate over the ArrayList was the only option: DO NOT use this code, continue reading to the bottom of this answer to see why it is not desirable, and which code should be used instead: In fact, a string concatenation is going … Read more

How do I iterate over the words of a string?

For what it’s worth, here’s another way to extract tokens from an input string, relying only on standard library facilities. It’s an example of the power and elegance behind the design of the STL. Instead of copying the extracted tokens to an output stream, one could insert them into a container, using the same generic copy algorithm. … Read more

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