Concatenating null strings in Java [duplicate]

Why must it work? The JLS 5, Section 15.18.1.1 JLS 8 § 15.18.1 “String Concatenation Operator +”, leading to JLS 8, § 5.1.11 “String Conversion”, requires this operation to succeed without failure: …Now only reference values need to be considered. If the reference is null, it is converted to the string “null” (four ASCII characters … Read more

Can I use require(“path”).join to safely concatenate urls?

No. path.join() will return incorrect values when used with URLs. It sounds like you want new URL(). From the WHATWG URL Standard: new URL(‘/one’, ‘http://example.com/’).href // ‘http://example.com/one’ new URL(‘/two’, ‘http://example.com/one’).href // ‘http://example.com/two’ Note that url.resolve is now marked as deprecated in the Node docs. As Andreas correctly points out in a comment, url.resolve (also deprecated) … Read more

Android TextView : “Do not concatenate text displayed with setText”

Resource has the get overloaded version of getString which takes a varargs of type Object: getString(int, java.lang.Object…). If you setup correctly your string in strings.xml, with the correct place holders, you can use this version to retrieve the formatted version of your final String. E.g. <string name=”welcome_messages”>Hello, %1$s! You have %2$d new messages.</string> using getString(R.string.welcome_message, … Read more

How to create a SQL Server function to “join” multiple rows from a subquery into a single delimited field? [duplicate]

If you’re using SQL Server 2005, you could use the FOR XML PATH command. SELECT [VehicleID] , [Name] , (STUFF((SELECT CAST(‘, ‘ + [City] AS VARCHAR(MAX)) FROM [Location] WHERE (VehicleID = Vehicle.VehicleID) FOR XML PATH (”)), 1, 2, ”)) AS Locations FROM [Vehicle] It’s a lot easier than using a cursor, and seems to work … Read more

How to concatenate strings with padding in sqlite

The || operator is “concatenate” – it joins together the two strings of its operands. From http://www.sqlite.org/lang_expr.html For padding, the seemingly-cheater way I’ve used is to start with your target string, say ‘0000’, concatenate ‘0000423’, then substr(result, -4, 4) for ‘0423’. Update: Looks like there is no native implementation of “lpad” or “rpad” in SQLite, … Read more

How to set the id attribute of a HTML element dynamically with angularjs (1.x)?

ngAttr directive can totally be of help here, as introduced in the official documentation https://docs.angularjs.org/guide/interpolation#-ngattr-for-binding-to-arbitrary-attributes For instance, to set the id attribute value of a div element, so that it contains an index, a view fragment might contain <div ng-attr-id=”{{ ‘object-‘ + myScopeObject.index }}”></div> which would get interpolated to <div id=”object-1″></div>

Using LINQ to concatenate strings

This answer shows usage of LINQ (Aggregate) as requested in the question and is not intended for everyday use. Because this does not use a StringBuilder it will have horrible performance for very long sequences. For regular code use String.Join as shown in the other answer Use aggregate queries like this: string[] words = { … Read more