HTML Format in UITextView

The problem there is that you have to change the Character Encoding options from NSUnicodeStringEncoding to NSUTF8StringEncoding to load your of your html the proper way. I think you should create a string extension read-only computed property to convert your html code to attributed string: Xcode 8.3.1 • Swift 3.1 extension Data { var attributedString: … Read more

SQL date format convert? [dd.mm.yy to YYYY-MM-DD]

Since your input is a string in the form 03.09.13, I’ll assume (since today is September 3, 2013) that it’s dd.mm.yy. You can convert it to a date using STR_TO_DATE: STR_TO_DATE(myVal, ‘%d.%m.%y’) Then you can format it back to a string using DATE_FORMAT: DATE_FORMAT(STR_TO_DATE(myVal, ‘%d.%m.%y’), ‘%Y-%m-%d’) Note that the year is %y (lowercase “y”) in … Read more

Java Date Format for Locale

DateFormat.getDateInstance(int,Locale) For example: import static java.text.DateFormat.*; DateFormat f = getDateInstance(SHORT, Locale.ENGLISH); Then you can use this object to format Dates: String d = f.format(new Date()); If you actually want to know the underlying pattern (e.g. yyyy-MMM-dd) then, as you’ll get a SimpleDateFormat object back: SimpleDateFormat sf = (SimpleDateFormat) f; String p1 = sf.toPattern(); String p2 … Read more

C++: how to get fprintf results as a std::string w/o sprintf

Here’s the idiom I like for making functionality identical to ‘sprintf’, but returning a std::string, and immune to buffer overflow problems. This code is part of an open source project that I’m writing (BSD license), so everybody feel free to use this as you wish. #include <string> #include <cstdarg> #include <vector> #include <string> std::string format … Read more

Align cout format as table’s columns

setw. #include <iostream> #include <iomanip> using namespace std; int main () { cout << setw(21) << left << “Test” << 1 << endl; cout << setw(21) << left << “Test2” << 2 << endl; cout << setw(21) << left << “Iamlongverylongblah” << 2 << endl; cout << setw(21) << left << “Etc” << 1 << … Read more