How do I concatenate const/literal strings in C?

In C, "strings" are just plain char arrays. Therefore, you can't directly concatenate them with other "strings". You can use the strcat function, which appends the string pointed to by src to the en... Read More

c# - How can I truncate my strings with a "..." if they are too long?

Here is the logic wrapped up in an extension method: public static string Truncate(this string value, int maxChars) { return value.Length <= maxChars ? value : value.Substring(0, maxChars) + "...... Read More

java - How can a string be initialized using " "?

Java String is Special The designers of Java decided to retain primitive types in an object-oriented language, instead of making everything an object, so as to improve the performance of the languag... Read More

javascript - Converting an object to a string

I would recommend using JSON.stringify, which converts the set of the variables in the object to a JSON string. Most modern browsers support this method natively, but for those that don't, you can in... Read More

Create a hexadecimal colour based on a string with JavaScript

Here's an adaptation of CD Sanchez' answer that consistently returns a 6-digit colour code: var stringToColour = function(str) { var hash = 0; for (var i = 0; i < str.length; i++) { hash = st... Read More

string - Upper vs Lower Case

Converting to either upper case or lower case in order to do case-insensitive comparisons is incorrect due to "interesting" features of some cultures, particularly Turkey. Instead, use a StringCompar... Read More

iphone - ObjectiveC Parse Integer from String

I really don't know what was so hard about this question, but I managed to do it this way: [myStringContainingInt intValue]; It should be noted that you can also do: myStringContainingInt.intValue;... Read More

c# - Best way to split string into lines

If it looks ugly, just remove the unnecessary ToCharArray call. If you want to split by either \n or \r, you've got two options: Use an array literal – but this will give you empty lines for Window... Read More

regex - Regular Expression Match to test for a valid year

Years from 1000 to 2999 ^[12][0-9]{3}$ For 1900-2099 ^(19|20)\d{2}$... Read More

c# - Why use String.Format?

I can see a number of reasons: Readability string s = string.Format("Hey, {0} it is the {1}st day of {2}. I feel {3}!", _name, _day, _month, _feeling); vs: string s = "Hey," + _name + " it is the "... Read More