Java split string to array [duplicate]

This behavior is explicitly documented in String.split(String regex) (emphasis mine): This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array. If you want those trailing empty strings included, you need to use String.split(String … Read more

How do I append one string to another in Python?

If you only have one reference to a string and you concatenate another string to the end, CPython now special cases this and tries to extend the string in place. The end result is that the operation is amortized O(n). e.g. used to be O(n^2), but now it is O(n). From the source (bytesobject.c): It’s … Read more

‘str’ object does not support item assignment

In Python, strings are immutable, so you can’t change their characters in-place. You can, however, do the following: The reasons this works is that it’s a shortcut for: The above creates a new string with each iteration, and stores the reference to that new string in s2.

Regex not operator

No, there’s no direct not operator. At least not the way you hope for. You can use a zero-width negative lookahead, however: The (?!…) part means “only match if the text following (hence: lookahead) this doesn’t (hence: negative) match this. But it doesn’t actually consume the characters it matches (hence: zero-width). There are actually 4 … Read more

Creating multiline strings in JavaScript

Update: ECMAScript 6 (ES6) introduces a new type of literal, namely template literals. They have many features, variable interpolation among others, but most importantly for this question, they can be multiline. A template literal is delimited by backticks: (Note: I’m not advocating to use HTML in strings) Browser support is OK, but you can use … Read more

What is `CString`?

CString is neither a C nor a C++ type. It appears to be a Microsoft invention that is essentially an alternative to std::string: CString objects can grow as a result of concatenation operations. CString objects follow “value semantics.” Think of a CString object as an actual string, not as a pointer to a string. You can freely substitute CString objects for const char* and LPCTSTR function arguments. A conversion … Read more

How can I exclude one word with grep?

You can do it using -v (for –invert-match) option of grep as: grep -v “unwanted_word” file will filter the lines that have the unwanted_word and grep XXXXXXXX will list only lines with pattern XXXXXXXX. EDIT: From your comment it looks like you want to list all lines without the unwanted_word. In that case all you need is:

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