concatenation

php truncate string if longer than limit and put some omission at the end..similar to ruby

半城伤御伤魂 提交于 2019-11-30 08:49:16
问题 I need this functionality in my recent php code many times, So I am lookin for a function to do the work, if there exists any.. If the string if bigger than the limit truncate it and put some omission text like ...(continued) .. Like in ruby we have truncate function on string "And they found that many people were sleeping better.".truncate(25, :omission => "... (continued)") I could do it by first checking the length exceeds.. then trim, then concatenation...But I am looking for some

C Macro Token Concatenation involving a variable - is it possible?

二次信任 提交于 2019-11-30 08:30:00
问题 I'm trying to define a macro to generate a token name, containing a variable. Basically, what I'm trying is this: #define GLUER(x,y,z) x##y##z #define PxDIR(x) GLUER(P,x,DIR) int main() { int port; port = 2; PxDIR(port) |= 0x01; } I'm hoping to generate the token P2DIR in the above statement, but according to my compiler output, it's generating the token PportDIR, which is NOT what I wanted. Any help here? Or is what I'm attempting to do impossible? 回答1: I don't think what you're trying to do

JavaScript concat string with backspace

社会主义新天地 提交于 2019-11-30 08:25:39
问题 I have a function f similar to function f(str){ alert("abc"+str); } Now, I want to use JavaScript special charecter "\b" in such a way that I can choose if I want to display the hardcoded string "abc" or not. For example, f("\b\b"+"yz"); //should output "ayz" I tried the same, but it does not work. In other words, I want to concat a string with a backspace character so that I can remove last characters from the string. Can we do this in JavaScript? EDIT The real code is too much big (its a

R: Merge of rows in same data table, concatenating certain columns

喜你入骨 提交于 2019-11-30 07:19:04
I have my data table in R. I want to merge rows which have an identical customerID , and then concatenate the elements of other merged columns. I want to go from this: title author customerID 1 title1 author1 1 2 title2 author2 2 3 title3 author3 1 to this: title author Group.1 1 title1, title3 author1, author3 1 2 title2 author2 2 The aggregate function should help you in finding a solution: dat = data.frame(title = c("title1", "title2", "title3"), author = c("author1", "author2", "author3"), customerID = c(1, 2, 1)) aggregate(dat[-3], by=list(dat$customerID), c) # Group.1 title author # 1 1

Batch string concatenation in Excel

孤者浪人 提交于 2019-11-30 07:03:38
问题 I have a couple hundred of cells in Excel I would like to concatenate into a single string. Is there a simpler method of doing this than going through them one by one manually in order to type them into CONCATENATE(A1, A2, ....) ? CONCATENATE(A1:A255) does not work. 回答1: *In a new tab, type A1 in cell A1, *Type A2 in Cell A2 *Use fill series to complete the values in column A *Type A1 in cell B1 Use this forumal in cell B2 =B1&","&A2 Copy the formula down. Copy and paste values to harvest the

Numpy: Concatenating multidimensional and unidimensional arrays

风流意气都作罢 提交于 2019-11-30 06:45:19
I have a 2x2 numpy array : x = array(([[1,2],[4,5]])) which I must merge (or stack, if you wish) with a one-dimensional array : y = array(([3,6])) by adding it to the end of the rows, thus making a 2x3 numpy array that would output like so : array([[1, 2, 3], [4, 5, 6]]) now the proposed method for this in the numpy guides is : hstack((x,y)) however this doesn't work, returning the following error : ValueError: arrays must have same number of dimensions The only workaround possible seems to be to do this : hstack((x, array(([y])).T )) which works, but looks and sounds rather hackish. It seems

How many Strings are created in memory?

落花浮王杯 提交于 2019-11-30 06:01:32
问题 Say I have this String expression String hi = "Tom" + "Brady" + "Goat" I know that the String pool "allows a runtime to save memory by preserving immutable strings in a pool" String Pool How many strings will be created in the string pool? My initial guess was 5 - "Tom" , "Brady" , "Goat" , "TomBrady" , "TomBradyGoat" , because of the order of operations of String concatenation (left to right?) or is it only the final result, "TomBradyGoat", that is stored in the String pool? 回答1: At runtime,

listagg data to useable format?

谁都会走 提交于 2019-11-30 06:01:00
问题 This is my first time working with the LISTAGG function and I'm confused. I can select the data easily enough, but the characters of the USERS column all have spaces in between them, and when trying to copypaste it, no data from that column is copied. I've tried with two different IDEs. Am I doing something wrong? Example: select course_id, listagg(firstname, ', ') within group (order by course_id) as users from ( select distinct u.firstname, u.lastname, u.student_id, cm.course_id from course

Concatenate quoted macro variables

馋奶兔 提交于 2019-11-30 05:35:52
问题 I'm just trying to concatenate two quoted macro variables but there doesn't seem to be an easy way. Say we have: %LET VAR1="This is not the greatest song in the world"; %LET VAR2="this is just a tribute."; %LET TRIBUTE=%SYSFUNC(CATX(%STR( ),&VAR1,&VAR2)); %PUT &TRIBUTE; I actually want: "This is not the greatest song in the world this is just a tribute." But the above code actually yields: "This is not the greatest song in the world" "this is just a tribute." So I try putting %QUOTE() ,

Efficient way to combine multiple text files

主宰稳场 提交于 2019-11-30 04:51:07
I have multiple files of text that I need to read and combine into one file. The files are of varying size: 1 - 50 MB each. What's the most efficient way to combine these files without bumping into the dreading System.OutofMemoryException ? Do it in chunks: const int chunkSize = 2 * 1024; // 2KB var inputFiles = new[] { "file1.dat", "file2.dat", "file3.dat" }; using (var output = File.Create("output.dat")) { foreach (var file in inputFiles) { using (var input = File.OpenRead(file)) { var buffer = new byte[chunkSize]; int bytesRead; while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)