Sorting Characters Of A C++ String

There is a sorting algorithm in the standard library, in the header <algorithm>. It sorts inplace, so if you do the following, your original word will become sorted. If you don’t want to lose the original, make a copy first.

How does String substring work in Swift

All of the following examples use Swift 4 Strings got a pretty big overhaul in Swift 4. When you get some substring from a String now, you get a Substring type back rather than a String. Why is this? Strings are value types in Swift. That means if you use one String to make a new one, then … Read more

std::string formatting like sprintf

Modern C++ makes this super simple. C++20 C++20 introduces std::format, which allows you to do exactly that. It uses replacement fields similar to those in python: Code from cppreference.com, CC BY-SA and GFDL Check out the compiler support page to see if it’s available in your standard library implementation. As of 2021-11-28, full support is only available in Visual Studio 2019 16.10, which … Read more

C – The %x format specifier

Break-down: 8 says that you want to show 8 digits 0 that you want to prefix with 0‘s instead of just blank spaces x that you want to print in lower-case hexadecimal. Quick example (thanks to Grijesh Chauhan): Output: Also see http://www.cplusplus.com/reference/cstdio/printf/ for reference.

How do I apply the for-each loop to every character in a String?

The easiest way to for-each every char in a String is to use toCharArray(): This gives you the conciseness of for-each construct, but unfortunately String (which is immutable) must perform a defensive copy to generate the char[] (which is mutable), so there is some cost penalty. From the documentation: [toCharArray() returns] a newly allocated character array whose length is the length of this string and whose contents are … Read more

Is a new line = \n OR \r\n?

\n is used for Unix systems (including Linux, and OSX). \r\n is mainly used on Windows. \r is used on really old Macs. PHP_EOL constant is used instead of these characters for portability between platforms.

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