string-concatenation

String concatenation in EL for dynamic ResourceBundle key

不问归期 提交于 2019-11-26 09:40:01
问题 I have a resource bundle with entries like these: entry1=value1 entry2=value2 entry3=value3 In my JSF page I\'m trying to use these keys dynamically. The ID of the entry is coming from a managed bean. I think it should be something like this: <h:outputText value=\"#{msg[\'entry\' managedBean.entryIndex]}\"/> How can I achieve this? 回答1: If you're already on Servlet 3.1 / EL 3.0 (Tomcat 8, WildFly 8, GlassFish 4, etc), make use of new EL 3.0 += operator: <h:outputText value="#{msg['entry' +=

Concatenate row-wise across specific columns of dataframe

放肆的年华 提交于 2019-11-26 09:31:11
问题 I have a data frame with columns that, when concatenated (row-wise) as a string, would allow me to partition the data frame into a desired form. > str(data) \'data.frame\': 680420 obs. of 10 variables: $ A : chr \"2011-01-26\" \"2011-01-26\" \"2011-02-09\" \"2011-02-09\" ... $ B : chr \"2011-01-26\" \"2011-01-27\" \"2011-02-09\" \"2011-02-10\" ... $ C : chr \"2011-01-26\" \"2011-01-26\" \"2011-02-09\" \"2011-02-09\" ... $ D : chr \"AAA\" \"AAA\" \"BCB\" \"CCC\" ... $ E : chr \"A00001\" \

Java String literals concatenation

依然范特西╮ 提交于 2019-11-26 09:12:48
问题 public static void main(String[] args){ one(); two(); three(); } public static void one() { String s1 = \"hill5\"; String s2 = \"hill\" + 5; System.out.println(s1==s2); } public static void two() { String s1 = \"hill5\"; int i =5; String s2 = \"hill\" + i; System.out.println(s1==s2); } public static void three() { String s1 = \"hill5\"; String s2 = \"hill\" + s1.length(); System.out.println(s1==s2); } Output is true false false String literals use interning process,then why two() and three()

How is String concatenation implemented in Java 9?

拟墨画扇 提交于 2019-11-26 08:49:11
问题 As written in JEP 280: Indify String Concatenation: Change the static String -concatenation bytecode sequence generated by javac to use invokedynamic calls to JDK library functions. This will enable future optimizations of String concatenation without requiring further changes to the bytecode emmited by javac . Here I want to understand what the use of invokedynamic calls is and how bytecode concatenation is different from invokedynamic ? 回答1: The "old" way output a bunch of StringBuilder

String concatenation in Ruby

拜拜、爱过 提交于 2019-11-26 08:42:59
问题 I am looking for a more elegant way of concatenating strings in Ruby. I have the following line: source = \"#{ROOT_DIR}/\" << project << \"/App.config\" Is there a nicer way of doing this? And for that matter what is the difference between << and + ? 回答1: You can do that in several ways: As you shown with << but that is not the usual way With string interpolation source = "#{ROOT_DIR}/#{project}/App.config" with + source = "#{ROOT_DIR}/" + project + "/App.config" The second method seems to be

Does concatenating strings in Java always lead to new strings being created in memory?

时光毁灭记忆、已成空白 提交于 2019-11-26 08:25:34
问题 I have a long string that doesn\'t fit the width of the screen. For eg. String longString = \"This string is very long. It does not fit the width of the screen. So you have to scroll horizontally to read the whole string. This is very inconvenient indeed.\"; To make it easier to read, I thought of writing it this way - String longString = \"This string is very long.\" + \"It does not fit the width of the screen.\" + \"So you have to scroll horizontally\" + \"to read the whole string.\" + \

String concatenation vs. interpolation in Ruby

我怕爱的太早我们不能终老 提交于 2019-11-26 08:09:59
问题 I am just starting to learn Ruby (first time programming), and have a basic syntactical question with regards to variables, and various ways of writing code. Chris Pine\'s \"Learn to Program\" taught me to write a basic program like this... num_cars_again= 2 puts \'I own \' + num_cars_again.to_s + \' cars.\' This is fine, but then I stumbled across the tutorial on ruby.learncodethehardway.com, and was taught to write the same exact program like this... num_cars= 2 puts \"I own #{num_cars}

How to concatenate strings with padding in sqlite

对着背影说爱祢 提交于 2019-11-26 08:01:31
问题 I have three columns in an sqlite table: Column1 Column2 Column3 A 1 1 A 1 2 A 12 2 C 13 2 B 11 2 I need to select Column1-Column2-Column3 (e.g. A-01-0001 ). I want to pad each column with a - I am a beginner with regards to SQLite, any help would be appreciated 回答1: 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',

How do I concatenate strings in Swift?

狂风中的少年 提交于 2019-11-26 07:59:14
问题 How to concatenate string in Swift? In Objective-C we do like NSString *string = @\"Swift\"; NSString *resultStr = [string stringByAppendingString:@\" is a new Programming Language\"]; or NSString *resultStr=[NSString stringWithFormat:@\"%@ is a new Programming Language\",string]; But I want to do this in Swift-language. 回答1: You can concatenate strings a number of ways: let a = "Hello" let b = "World" let first = a + ", " + b let second = "\(a), \(b)" You could also do: var c = "Hello" c +=

Using LINQ to concatenate strings

拥有回忆 提交于 2019-11-26 07:49:57
问题 What is the most efficient way to write the old-school: StringBuilder sb = new StringBuilder(); if (strings.Count > 0) { foreach (string s in strings) { sb.Append(s + \", \"); } sb.Remove(sb.Length - 2, 2); } return sb.ToString(); ...in LINQ? 回答1: 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