string-concatenation

Ruby on Rails - concatenate strings on save to database upon user clicking create action

牧云@^-^@ 提交于 2019-12-04 19:21:32
Its late and I probably should sleep on this. Easy one I have 3 fields in a form which a user fills in. Once they click the create button these records are saved to the database. Simple. However I want the data from these three fields at the same time to be concatenated together, nothing fancy..and inserted to the database at the same time as the other records. This should reflect back to the user on the show page after they create. So I need an action to concatenate 3 db columns lets say column names are firstname, surname and DOB. table name PeopleDetails I have tried building the model

How to build an HTML table with subtotals using a recursive string concatenation?

六眼飞鱼酱① 提交于 2019-12-04 11:44:58
I have the next two tables: CREATE TABLE #SalesByStore ( Brand VARCHAR(10), StoreName VARCHAR(50), Sales DECIMAL(10,2) ) CREATE TABLE #SalesByBrand ( Brand VARCHAR(10), TotalSales DECIMAL(10,2) ) I am trying to build an HTML table body using recursive string concatenation, and I need to show the sales by store ordered by brand, and after each group of stores from a same brand show the sales subtotals for that brand, like this: I am doing it the following way: DECLARE @tableBody NVARCHAR(MAX), @lastBrand VARCHAR(10); SELECT @tableBody=''; SELECT @tableBody = @tableBody + CASE WHEN @lastBrand IS

Operation overloading in R [duplicate]

守給你的承諾、 提交于 2019-12-04 09:16:34
This question already has an answer here: Making a string concatenation operator in R 5 answers What's the most straight forward way of overloading '+' for characters? I have defined '%+%' <- function(...) paste(...,sep="") : str <- "aa"%+%"bb"%+%"cc" #str="aabbcc" But I don't like the syntax. I think str <- "aa"+"bb"+"cc" would be nicer. (I am building long SQL queries to use with RODBC, the usual paste is not very handy in such situations. Any suggestions?) I think that using two arguments is better than the dots: '%+%' <- function(x,y) paste(x,y,sep="") "a"%+%"b"%+%"C" [1] "abC" If you

How do I concatenate the string elements of my array into a single string in C?

寵の児 提交于 2019-12-04 07:13:16
问题 I have an array of strings and I would like to create a new string that is a concatenation of all the array elements. Any help is appreciated, thanks 回答1: #include <stdio.h> #include <stdlib.h> #include <string.h> char *concatenate(size_t size, char *array[size], const char *joint){ size_t jlen, lens[size]; size_t i, total_size = (size-1) * (jlen=strlen(joint)) + 1; char *result, *p; for(i=0;i<size;++i){ total_size += (lens[i]=strlen(array[i])); } p = result = malloc(total_size); for(i=0;i

Why is concatenating SQL strings a bad idea?

好久不见. 提交于 2019-12-04 03:45:38
问题 I have read that it's a bad idea to concatenate SQL strings like so: cmd.CommandText = "Insert INTO workers Values (" + User.Identity.Name + "," + WorkerName.Text + "," + GetUniqueWorkerKey() + ");"; So the recommended way was: cmd.CommandText = "Insert INTO workers Values (@Username, @WorkerName, @WorkerKey)"; cmd.Parameters.AddWithValue("@Username", User.Identity.Name); cmd.Paramters.AddWithValue("@WorkerName", TheWorkerNameYouPassedToThisMethod); I have been avoiding concatenating SQL

C#: most readable string concatenation. best practice [duplicate]

风流意气都作罢 提交于 2019-12-03 23:42:35
This question already has answers here : Closed 9 years ago . Possible Duplicate: How should I concatenate strings? There are several ways to concat strings in everyday tasks when performance is not important . result = a + ":" + b result = string.Concat(a, ":", c) result = string.Format("{0}:{1}", a, b); StringBuilder approach ... ? what do you prefer and why if efficiency doesn't matter but you want to keep the code most readable for your taste? It depends on the use. When you just want to concat two strings, using a + b is just much more readable than string.Format("{0}{1}", a, b) . However

SQLite Update Syntax for string concatenation?

蓝咒 提交于 2019-12-03 15:09:36
问题 I have a table with this data id , name , description 1 , apple , '' 2 , orange , '' I am trying to pass the following statement to update the row so the description column is 'desc of apple' and 'desc of orange' but it is not working. Update TestTable Set description = 'desc of ' + name What is the proper syntax to concatenate strings? 回答1: SQLite's string concatenation operator is " || ", not " + " UPDATE TestTable SET description = 'desc of ' || name; 来源: https://stackoverflow.com

Concatenate two char arrays?

我只是一个虾纸丫 提交于 2019-12-03 10:30:23
If I have two char arrays like so: char one[200]; char two[200]; And I then want to make a third which concatenates these how could I do it? I have tried: char three[400]; strcpy(three, one); strcat(three, two); But this doesn't seem to work. It does if one and two are setup like this: char *one = "data"; char *two = "more data"; Anyone got any idea how to fix this? Thanks Martin Ingvar Kofoed Jensen If 'one' and 'two' does not contain a '\0' terminated string, then you can use this: memcpy(tree, one, 200); memcpy(&tree[200], two, 200); This will copy all chars from both one and two

How do you concatenate strings in a Puppet .pp file?

江枫思渺然 提交于 2019-12-03 08:06:04
问题 Here is my naive approach: # puppet/init.pp $x = 'hello ' + 'goodbye' This does not work. How does one concatenate strings in Puppet? 回答1: Keyword variable interpolation: $value = "${one}${two}" Source: http://docs.puppetlabs.com/puppet/4.3/reference/lang_variables.html#interpolation Note that although it might work without the curly braces, you should always use them. 回答2: I use the construct where I put the values into an array an then 'join' them. In this example my input is an array and

Performance: Java's String.format [duplicate]

 ̄綄美尐妖づ 提交于 2019-12-03 06:01:00
Possible Duplicate: Should I use Java's String.format() if performance is important? I was wondering if is good to use String.format in Java apps instead of StringBuilder ... so, I just write a simple test, like this: public static void main(String[] args) { int i = 0; Long start = System.currentTimeMillis(); while (i < 10000) { String s = String.format("test %d", i); i++; } System.out.println(System.currentTimeMillis() - start); i = 0; start = System.currentTimeMillis(); while (i < 10000) { String s = new StringBuilder().append("test ").append(i).toString(); i++; } System.out.println(System