string-concatenation

Create comma separated strings C#?

落爺英雄遲暮 提交于 2019-11-27 02:01:58
问题 I have an object which holds many values, some of them (not all values from the object) need to be put in a csv string. My approach was this: string csvString = o.number + "," + o.id + "," + o.whatever .... Somehow I think there is a better, more elegant way? 回答1: If you put all your values in an array, at least you can use string.Join . string[] myValues = new string[] { ... }; string csvString = string.Join(",", myValues); You can also use the overload of string.Join that takes params

Concatenate many rows into a single text string with grouping [duplicate]

给你一囗甜甜゛ 提交于 2019-11-27 01:59:38
问题 This question already has answers here : Can I Comma Delimit Multiple Rows Into One Column? [duplicate] (5 answers) Closed 6 years ago . I have the following table: tblFile My Desired output: I am Concatenating many rows into a single text string; however, I cannot get the grouping correct. As the code is now it will just display for each record in the FileNameString field: AAA,BBB,CCC,DDD,EEE,FFF Any suggestions with the grouping! SELECT FileID, Stuff( (SELECT N', ' + CONVERT(Varchar,

Is string concatenaion really that slow?

末鹿安然 提交于 2019-11-27 01:51:10
问题 I'm currently looking into String concat options and the penalty they have on the overall performance. And my test-case creates results that blow my mind, I'm not sure if I'm overlooking something. Here is the deal: Doing "something"+"somethingElse" in java will (at compile-time) create a new StringBuilder every time this is done. For my test-case, I'm loading a file from my HDD that has 1661 lines of example data (classic "Lorem Ipsum"). This question is not about the I/O performance , but

String concatenation in EL for dynamic ResourceBundle key

混江龙づ霸主 提交于 2019-11-27 01:27:39
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? 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' += managedBean.entryIndex]}" /> If you're only on Servlet 3.0 / EL 2.2 (Tomcat 7, JBoss AS 6/7, GlassFish 3, etc),

Simple string concatenation in Objective C

霸气de小男生 提交于 2019-11-27 01:01:43
问题 I have an NSString named 'you' with value "This is a you string!". I want to concat "123" in 'you', how can I do it? I am using this code and it is giving an error. you=[you stringByAppendingString:@"123"]; 回答1: This code here is working for me NSString *s = @"avant"; s = [s stringByAppendingString:@" - après"]; NSLog(@"%@", s); 2012-01-13 11:48:59.442 tabbar[604:207] avant - après So my guess is that your you is a bad pointer that is not nil and not the NSString you think it have. Have you

JavaScript String concatenation behavior with null or undefined values

白昼怎懂夜的黑 提交于 2019-11-27 00:40:30
问题 As you may know, in JavaScript '' + null = "null" and '' + undefined = "undefined" (in most browsers I can test: Firefox, Chrome and IE). I would like to know the origin of this oddity (what the heck was in the head on Brendan Eich?!) and if there is any aim for changing it in a future version of ECMA. It's indeed pretty frustrating having to do 'sthg' + (var || '') for concatenating Strings with variables and using a third party framework like Underscore or other for that is using a hammer

Best practices/performance: mixing StringBuilder.append with String.concat

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 23:48:29
问题 I'm trying to understand what the best practice is and why for concatenating string literals and variables for different cases. For instance, if I have code like this StringBuilder sb = new StringBuilder("AAAAAAAAAAAAA") .append(B_String).append("CCCCCCCCCCC").append(D_String) .append("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE") .append("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); Is this the way to do it? From this post, I noticed that the + operator on

String concatenation in Ruby

回眸只為那壹抹淺笑 提交于 2019-11-26 23:23:20
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 + ? Keltia 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 more efficient in term of memory/speed from what I've seen (not measured though). All three methods will

Why is 'new_file += line + string' so much faster than 'new_file = new_file + line + string'? [duplicate]

情到浓时终转凉″ 提交于 2019-11-26 23:09:35
问题 This question already has an answer here: Why is variable1 += variable2 much faster than variable1 = variable1 + variable2? 1 answer Our code takes 10 minutes to siphon thru 68,000 records when we use: new_file = new_file + line + string However when we do the following it takes just 1 second: new_file += line + string Here is the code: for line in content: import time import cmdbre fname = "STAGE050.csv" regions = cmdbre.regions start_time = time.time() with open(fname) as f: content = f

Java String literals concatenation

不羁岁月 提交于 2019-11-26 23:00:53
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() is false.I can understand in case of three() but two() is not clear.but need proper explanation for both cases. Can