string-concatenation

String.Join performance issue in C#

谁都会走 提交于 2019-12-19 05:23:31
问题 I've been researching a question that was presented to me: How to write a function that takes a string as input and returns a string with spaces between the characters. The function is to be written to optimize performance when it is called thousands of times per second. I know that .net has a function called String.Join , to which I may pass in the space character as a separator along with the original string. Barring the use of String.Join , I can use the StringBuilder class to append

How do you append to an already existing string?

∥☆過路亽.° 提交于 2019-12-18 10:11:25
问题 I want append to a string so that every time I loop over it will add say "test" to the string. Like in PHP you would do: $teststr = "test1\n" $teststr .= "test2\n" echo = "$teststr" echos: test1 test2 But I need to do this in a shell script 回答1: In classic sh, you have to do something like: s=test1 s="${s}test2" (there are lots of variations on that theme, like s="$s""test2" ) In bash, you can use +=: s=test1 s+=test2 回答2: $ string="test" $ string="${string}test2" $ echo $string testtest2 回答3

concatenating string

半世苍凉 提交于 2019-12-18 09:03:22
问题 Is there a way in SQL sever that can write the output as follow: select events from mytable original output events -------- 123456 894531 985233 829292 920202 392939 299223 desired output '123456', '894531','985233','829292','920202','392939','299223' select '' + CustomerID + ',' from dbo.Customers customerid ALFKI, ANATR, ANTON, AROUT, BERGS, Would like to see the result as customerid 'ALFKI', 'ANATR', 'ANTON', 'AROUT', 'BERGS', so on... 回答1: SELECT STUFF( (SELECT ', ' + events FROM dbo

T-SQL: issue with string concat

陌路散爱 提交于 2019-12-18 07:38:30
问题 I have a set of audio files with names GreenLine1.mp3, GreenLine2.mp3 e.t.c. I'm going to write them into a table as BLOB (I use MS SQL Server'08), here's my sql request: DECLARE @aud AS VARBINARY(MAX) DECLARE @num AS INT -- Load the audio data SET @num=1 WHILE (@num<38) BEGIN; SELECT @aud = CAST(bulkcolumn AS VARBINARY(MAX)) FROM OPENROWSET( BULK 'C:\Users\Ilya\folder\GreenLine' + CAST(@num AS VARCHAR) + '.mp3', SINGLE_BLOB ) AS x -- Insert the data to the table INSERT INTO Mb2.dbo.Audios

T-SQL: issue with string concat

本小妞迷上赌 提交于 2019-12-18 07:37:39
问题 I have a set of audio files with names GreenLine1.mp3, GreenLine2.mp3 e.t.c. I'm going to write them into a table as BLOB (I use MS SQL Server'08), here's my sql request: DECLARE @aud AS VARBINARY(MAX) DECLARE @num AS INT -- Load the audio data SET @num=1 WHILE (@num<38) BEGIN; SELECT @aud = CAST(bulkcolumn AS VARBINARY(MAX)) FROM OPENROWSET( BULK 'C:\Users\Ilya\folder\GreenLine' + CAST(@num AS VARCHAR) + '.mp3', SINGLE_BLOB ) AS x -- Insert the data to the table INSERT INTO Mb2.dbo.Audios

Getting unicode string from its code - C#

醉酒当歌 提交于 2019-12-17 22:18:57
问题 I know following is the way to use unicode in C# string unicodeString = "\u0D15"; In my situation, I will not get the character code ( 0D15 ) at compile time. I get this from a XML file at runtime. I wonder how do I convert this code to unicode string? I tried the following // will not compile as unrecognized escape sequence string unicodeString = "\u" + codeFromXML; // will compile, but just concatenates u with the string got from XML file. string unicodeString = "\\u" + codeFromXML; How do

How to construct a std::string from a std::vector<string>?

对着背影说爱祢 提交于 2019-12-17 22:10:53
问题 I'd like to build a std::string from a std::vector<std::string> . I could use std::stringsteam , but imagine there is a shorter way: std::string string_from_vector(const std::vector<std::string> &pieces) { std::stringstream ss; for(std::vector<std::string>::const_iterator itr = pieces.begin(); itr != pieces.end(); ++itr) { ss << *itr; } return ss.str(); } How else might I do this? 回答1: C++03 std::string s; for (std::vector<std::string>::const_iterator i = v.begin(); i != v.end(); ++i) s += *i

Can MySQL concatenate strings with ||

我怕爱的太早我们不能终老 提交于 2019-12-17 20:34:59
问题 I'm using sqlite3 for the moment, and hence concatenation strings using the || operator. At some later date I'd like to shift to MySQL, and hence it would be nice if no changes to the code had to be made. I'd normally use concat() to concatenate in MySQL. Does || work too, or will I have to modify my code? Or is there any other solution? I'm coding in Ruby on Rails 3.1, by the way. 回答1: The || works in MySQL as well but you need to set sql_mode to PIPES_AS_CONCAT . Official Doc Demo: mysql>

Format specifier for integer variables in format() for EXECUTE?

梦想的初衷 提交于 2019-12-17 19:44:21
问题 CREATE OR REPLACE FUNCTION getParentLtree(parent_id bigint, tbl_name varchar) RETURNS ltree AS $BODY$ DECLARE parent_ltree ltree; BEGIN -- This works fine: -- select into parent_ltree l_tree from tbl1 where id = parent_id; EXECUTE format('select into parent_ltree l_tree from %I where id = %I', tbl_name,parent_id); RETURN parent_ltree; END; $BODY$ LANGUAGE plpgsql; There are 2 issues in above function: parent_id is integer but it is replaced with quotes? What is the correct format specifier

Concatenate multiple results from an index match

拈花ヽ惹草 提交于 2019-12-17 19:29:29
问题 I'm trying to concat multiple results from an index match into one cell. Here is an example data set I'm working with: My desired results: As you can see, I'm trying to find all customers where the data is 4/12/2017. I then want to combine them into one string in another cell. I've figured out how to sum up the quantity if the date is the same, but just can't figure out how to concatenate the customer. 回答1: Use the newer TEXTJOIN function as an array formula with CSE. =textjoin("|", true, if