concatenation

When is StringBuffer/StringBuilder not implicitly used by the compiler?

半城伤御伤魂 提交于 2019-11-30 23:53:34
问题 I've heard that the compiler (or was it the JVM?) will automatically use a StringBuilder for some string concatenation. When is the right time to explicitly declare one? I don't need a StringBuffer for being thread-safe. Thanks. 回答1: The compiler will use it automatically for any string concatenation using "+". You'd usually use it explicitly if you wanted to concatenate in a loop. For example: StringBuilder builder = new StringBuilder(); for (String name : names) { builder.append(name);

PHP - Concatenate if statement?

。_饼干妹妹 提交于 2019-11-30 23:36:04
I want to concatenate in the middle of an echo to write an if statement, is this possible? Here is what I have. echo "<li class='".if ($_GET["p"] == "home") { echo "active"; }."'><a href='#'>Home</a> </li>"; Like this, using the ternary operator : echo "<li class='". (($_GET["p"] == "home") ? "active" : "") . "'><a href='#'>Home</a> </li>"; Do like this: echo "<li class='".($_GET["p"] == "home" ? 'active' : '') ."'><a href='#'>Home</a> </li>"; echo "<li class='".(($_GET["p"] == "home") ? "active" : "")."'><a href='#'>Home</a> </li>"; Instead of messy inline concatenations, might I suggest

R: What are the best functions to deal with concatenating and averaging values in a data.frame?

走远了吗. 提交于 2019-11-30 23:33:10
I have a data.frame from this code: my_df = data.frame("read_time" = c("2010-02-15", "2010-02-15", "2010-02-16", "2010-02-16", "2010-02-16", "2010-02-17"), "OD" = c(0.1, 0.2, 0.1, 0.2, 0.4, 0.5) ) which produces this: > my_df read_time OD 1 2010-02-15 0.1 2 2010-02-15 0.2 3 2010-02-16 0.1 4 2010-02-16 0.2 5 2010-02-16 0.4 6 2010-02-17 0.5 I want to average the OD column over each distinct read_time (notice some are replicated others are not) and I also would like to calculate the standard deviation, producing a table like this: > my_df read_time OD stdev 1 2010-02-15 0.15 0.05 5 2010-02-16 0.3

How to merge 3 matrices into 1 in opencv?

随声附和 提交于 2019-11-30 23:13:44
I have three matrices, each of size 4x1 . I want to copy all of these matrices to another matrix of size 4x3 and call it R . Is there a smart way to do it? You can just use hconcat for horizontal concatenation. You can use it per matrix, e.g. hconcat( mat1, mat2, R ), or apply it directly on a vector or array of matrices. Here's a sample code: vector<Mat> matrices = { Mat(4, 1, CV_8UC1, Scalar(1)), Mat(4, 1, CV_8UC1, Scalar(2)), Mat(4, 1, CV_8UC1, Scalar(3)), }; Mat R; hconcat( matrices, R ); cout << R << endl; Here's the result: [1, 2, 3; 1, 2, 3; 1, 2, 3; 1, 2, 3] Program ended with exit

Concatenating strings in macros - C++

让人想犯罪 __ 提交于 2019-11-30 22:46:45
问题 What's the easiest way to concatenate strings defined in macros. i.e. The pseudo code I'm looking for would be like: #define ROOT_PATH "/home/david/" #define INPUT_FILE_A ROOT_PATH+"data/inputA.bin" #define INPUT_FILE_B ROOT_PATH+"data/inputB.bin" ... #define INPUT_FILE_Z ROOT_PATH+"data/inputZ.bin" The only way I know of is to use strcat in the code, or using the string class and then the c_str method, but it can get messy when I have lots of input files. I'd like to just use INPUT_FILE_A,

Concatenating two vectors in R [duplicate]

蓝咒 提交于 2019-11-30 19:25:42
This question already has an answer here: How to concatenate factors, without them being converted to integer level? 8 answers I want to concatenate two vectors one after the other in R. I have written the following code to do it: > a = head(tracks_listened_train) > b = head(tracks_listened_test) > a [1] cc1a46ee0446538ecf6b65db01c30cd8 19acf9a5cbed34743ce0ee42ef3cae3e [3] 9e7fdbf2045c9f814f6c0bed5da9bed7 3441b1031267fbb6009221bf47f9c5e8 [5] 206c8b79bd02beeea200879afc414879 1a7a95e3845a6815060628e847d14362 18585 Levels: 0001a423baf29add84af6ec58aeb5b90 ... > b [1]

Excel “UnCONCATENATE”/explode in function / Convert cell into array

馋奶兔 提交于 2019-11-30 19:12:02
问题 I am trying to "Unconcatenate" a string in Excel 2010. Yes, I know that is not a real word. So pretty much; I have a cell that can not be split into multiple columns the cell looks like this: Item 1, Item 2, Item 3 Now this cell may have 0-? items. I am wanting to compare that one cell against a column in another sheet. I believe I would need to use the match function to do this, but I need that first cell to be converted into an array in a function with the delimiter as the comma. So far I

String concatenation in a for loop. Java 9

北城以北 提交于 2019-11-30 18:21:42
Please correct me if i'm wrong. In Java 8, for performance reasons, when concatenating several strings by the "+" operator StringBuffer was invoked. And the problem of creating a bunch of intermediate string objects and polluting the string pool was "resolved". What about Java 9? There'a new feature added as Invokedynamic. And a new class that resolves the problem even better, StringConcatFactory. String result = ""; List<String> list = Arrays.asList("a", "b", "c"); for (String n : list) { result+=n; } My question are: How many objects are created in this loop? Are there any intermedier

Concatenate two numerical values to make a new column using pandas?

橙三吉。 提交于 2019-11-30 17:20:20
问题 I have two columns in my dataframe. var1 var2 01 001 I would like to create a third column that joins them together: var1 var2 var3 01 001 01001 Does anyone know how to do this? Thank you! 回答1: You can use simple concanecate by + with casting by astype: df['var3'] = df.var1.astype(str) + df.var2.astype(str) print df var1 var2 var3 0 01 001 01001 If type of both columns is string casting is omited: print type(df.loc[0,'var1']) <type 'str'> print type(df.loc[0,'var2']) <type 'str'> df['var3'] =

Concatenate multiple IEnumerable<T>

核能气质少年 提交于 2019-11-30 17:19:38
I'm trying to implement a method to concatenate multiple List s e.g. List<string> l1 = new List<string> { "1", "2" }; List<string> l2 = new List<string> { "1", "2" }; List<string> l3 = new List<string> { "1", "2" }; var result = Concatenate(l1, l2, l3); but my method doesn't work: public static IEnumerable<T> Concatenate<T>(params IEnumerable<T> List) { var temp = List.First(); for (int i = 1; i < List.Count(); i++) { temp = Enumerable.Concat(temp, List.ElementAt(i)); } return temp; } Use SelectMany : public static IEnumerable<T> Concatenate<T>(params IEnumerable<T>[] lists) { return lists