How to check if a String is numeric in Java

With Apache Commons Lang 3.5 and above: NumberUtils.isCreatable or StringUtils.isNumeric. With Apache Commons Lang 3.4 and below: NumberUtils.isNumber or StringUtils.isNumeric. You can also use StringUtils.isNumericSpace which returns true for empty strings and ignores internal spaces in the string. Another way is to use NumberUtils.isParsable which basically checks the number is parsable according to Java. (The … Read more

How to compress a String in Java?

Compression algorithms almost always have some form of space overhead, which means that they are only effective when compressing data which is sufficiently large that the overhead is smaller than the amount of saved space. Compressing a string which is only 20 characters long is not too easy, and it is not always possible. If … Read more

C++ string to enum

A std::map<std::string, MyEnum> (or unordered_map) could do it easily. Populating the map would be just as tedious as the switch statement though. Edit: Since C++11, populating is trivial:

Find the nth occurrence of substring in a string

Mark’s iterative approach would be the usual way, I think. Here’s an alternative with string-splitting, which can often be useful for finding-related processes: And here’s a quick (and somewhat dirty, in that you have to choose some chaff that can’t match the needle) one-liner:

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