string-concatenation

how to use concatenate a fixed string and a variable in Python

给你一囗甜甜゛ 提交于 2019-12-17 18:47:58
问题 I want to include file name 'main.txt' in the subject for that I am passing file name from command line. but getting error in doing so python sample.py main.txt #running python with argument msg['Subject'] = "Auto Hella Restart Report "sys.argv[1] #line where i am using that passed argument 回答1: I'm guessing that you meant to do this: msg['Subject'] = "Auto Hella Restart Report " + sys.argv[1] # To concatenate strings in python, use ^ 回答2: Try: msg['Subject'] = "Auto Hella Restart Report " +

How do I concatenate strings in Entity Framework Query?

…衆ロ難τιáo~ 提交于 2019-12-17 18:23:22
问题 How do I concatenate strings in Entity Framework 4 I have a data from a column and I want to save as a string a comma separated string like "value1, value2, value3" Is there a method or an operator do do this in EF4? Example: lets say that I have two columns Fruit and Farms with the following values: Apples Bananas Strawberries If I do like this var dataSource = this.context .Farms .Select(f => new { f.Id, Fruits = string.Join(", ", f.Fruits) }); Sure I will get this error LINQ to Entities

How to collapse a list of characters into a single string in R

风流意气都作罢 提交于 2019-12-17 16:42:03
问题 There is a list which I would like to output into an excel file as a single string. I start with a list of characters. url="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=21558518&retmode=xml" xml = xmlTreeParse(url,useInternal = T) ns <- getNodeSet(xml, '//PublicationTypeList/PublicationType') types <- sapply(ns, function(x) { xmlValue(x) } ) types Output is this: [1] "Journal Article" "Multicenter Study" "Research Support, N.I.H., Extramural" [4] "Research Support,

const char* concatenation

人走茶凉 提交于 2019-12-17 10:15:25
问题 I need to concatenate two const chars like these: const char *one = "Hello "; const char *two = "World"; How might I go about doing that? I am passed these char* s from a third-party library with a C interface so I can't simply use std::string instead. 回答1: In your example one and two are char pointers, pointing to char constants. You cannot change the char constants pointed to by these pointers. So anything like: strcat(one,two); // append string two to string one. will not work. Instead you

C++ equivalent of StringBuffer/StringBuilder?

感情迁移 提交于 2019-12-17 07:02:33
问题 Is there a C++ Standard Template Library class that provides efficient string concatenation functionality, similar to C#'s StringBuilder or Java's StringBuffer? 回答1: NOTE this answer has received some attention recently. I am not advocating this as a solution (it is a solution I have seen in the past, before the STL). It is an interesting approach and should only be applied over std::string or std::stringstream if after profiling your code you discover this makes an improvement. I normally

C++ equivalent of StringBuffer/StringBuilder?

这一生的挚爱 提交于 2019-12-17 07:01:29
问题 Is there a C++ Standard Template Library class that provides efficient string concatenation functionality, similar to C#'s StringBuilder or Java's StringBuffer? 回答1: NOTE this answer has received some attention recently. I am not advocating this as a solution (it is a solution I have seen in the past, before the STL). It is an interesting approach and should only be applied over std::string or std::stringstream if after profiling your code you discover this makes an improvement. I normally

Is this time complexity actually O(n^2)?

强颜欢笑 提交于 2019-12-17 04:27:57
问题 I am working on a problem out of CTCI. The third problem of chapter 1 has you take a string such as 'Mr John Smith ' and asks you to replace the intermediary spaces with %20 : 'Mr%20John%20Smith' The author offers this solution in Python, calling it O(n): def urlify(string, length): '''function replaces single spaces with %20 and removes trailing spaces''' counter = 0 output = '' for char in string: counter += 1 if counter > length: return output elif char == ' ': output = output + '%20' elif

How do I concatenate strings?

可紊 提交于 2019-12-17 03:28:09
问题 How do I concatenate the following combinations of types: str and str String and str String and String 回答1: When you concatenate strings, you need to allocate memory to store the result. The easiest to start with is String and &str : fn main() { let mut owned_string: String = "hello ".to_owned(); let borrowed_string: &str = "world"; owned_string.push_str(borrowed_string); println!("{}", owned_string); } Here, we have an owned string that we can mutate. This is efficient as it potentially

How to concatenate int values in java?

让人想犯罪 __ 提交于 2019-12-16 22:47:08
问题 I have the following values: int a=1; int b=0; int c=2; int d=2; int e=1; How do i concatenate these values so that i end up with a String that is 10221 ; please note that multiplying a by 10000, b by 1000.....and e by 1 will not working since b=0 and therefore i will lose it when i add the values up. 回答1: The easiest (but somewhat dirty) way: String result = "" + a + b + c + d + e Edit: I don't recommend this and agree with Jon's comment. Adding those extra empty strings is probably the best

How slow is Python's string concatenation vs. str.join?

北慕城南 提交于 2019-12-16 22:22:45
问题 As a result of the comments in my answer on this thread, I wanted to know what the speed difference is between the += operator and ''.join() So what is the speed comparison between the two? 回答1: From: Efficient String Concatenation Method 1: def method1(): out_str = '' for num in xrange(loop_count): out_str += 'num' return out_str Method 4: def method4(): str_list = [] for num in xrange(loop_count): str_list.append('num') return ''.join(str_list) Now I realise they are not strictly