concatenation

Ruby concatenate strings and add spaces

折月煮酒 提交于 2019-12-04 07:57:06
问题 I have 4 string variables name, quest, favorite_color, speed that might be empty. I want to concatenate them all together, putting spaces between those that aren't empty. Simplicity of the code, i.e how simple is to to look at and understand, is more important than speed. So: name = 'Tim' quest = 'destroy' favorite_color = 'red' speed = 'fast' becomes 'Tim destroy red fast' and name = 'Steve' quest = '' favorite_color = '' speed = 'slow' becomes: 'Steve slow' Note there is only 1 space

Concatenate hex numbers in C

跟風遠走 提交于 2019-12-04 07:15:23
I've been trying to concatenate 4 hex numbers and can't seem to do it. Example: int a = 0x01; int b = 0x00; int c = 0x20; int d = 0xF1; //Result should be 0x010020F1 The results that I am getting using sprintf and bitwise operations always cut off zeros, giving me answers like 1020F1, which is much different than what I want. Anybody have a better method? Supposing unsigned int a,b,c,d; unsigned int result = (a<<24) | (b<<16)| (c<<8) | d; But this is essentially implementation dependent since C++ standard only specifies minimal sizes of integers. So for uint32_t a, b, c, d : uint32_t result =

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

concatenating arrays in python like matlab without knowing the size of the output array

两盒软妹~` 提交于 2019-12-04 06:46:18
I am trying to concatenate arrays in python similar to matlab array1= zeros(3,500); array2=ones(3,700); array=[array1, array2]; I did the following in python: array1=np.zeros((3,500)) array2=np.ones((3,700)) array=numpy.concatenate((array1, array2), axis=2) however this gives me different results when i access try to "array[0,:]" is there a way in python to put arrays in one array similar to matlab. Thank you concatenate((a,b),1) or hstack((a,b)) or column_stack((a,b)) or c_[a,b] From here: http://wiki.scipy.org/NumPy_for_Matlab_Users 来源: https://stackoverflow.com/questions/18404077

Gstreamer pipeline to concat two media containers (video and audio streams)

最后都变了- 提交于 2019-12-04 05:13:10
问题 I am a beginner to gstreamer and struggling with a pipeline for Gstreamer 1.0 to concatenate seamlessly two MP4 media containers, both of them with video and audio streams. It seems to me that using "concat" element is the most convenient way, and I am able to concat either video streams: gst-launch-1.0 concat name=c ! autovideosink filesrc location=1.mp4 ! decodebin ! videoconvert ! c. filesrc location=2.mp4 ! decodebin ! videoconvert ! c. or audio streams: gst-launch-1.0 concat name=c !

String concatenation in Rails 3

流过昼夜 提交于 2019-12-04 04:27:12
I'm wondering why this is so: Ruby concatenates two strings if there is a space between the plus and the next string. But if there is no space, does it apply some unary operator? params['controller'].to_s + '/' # => "posts/" params['controller'].to_s +'/' # => NoMethodError: undefined method `+@' for "/":String The parser is interpreting +'/' as the first parameter to the to_s method call. It is treating these two statements as equivalent: > params['controller'].to_s +'/' # NoMethodError: undefined method `+@' for "/":String > params['controller'].to_s(+'/') # NoMethodError: undefined method `

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

How to “Implode” (de-normalize/concat) multiple columns into a single column?

被刻印的时光 ゝ 提交于 2019-12-04 02:59:53
问题 I have a query which outputs something like this: +-------+----+--------------+ | F_KEY | EV | OTHER_COLUMN | +-------+----+--------------+ | 100 | 1 | ... | | 100 | 2 | ... | | 150 | 2 | ... | | 100 | 3 | ... | | 150 | 4 | ... | +-------+----+--------------+ I'm sure that I've seen an aggregation function which turns it (using GROUP BY F_KEY ) into something like this: +-------+------------+--------------+ | F_KEY | ? | OTHER_COLUMN | +-------+------------+--------------+ | 100 | (1, 2, 3) |

Concatenation of 2 1D `numpy` Arrays Along 2nd Axis

蓝咒 提交于 2019-12-04 02:42:42
Executing import numpy as np t1 = np.arange(1,10) t2 = np.arange(11,20) t3 = np.concatenate((t1,t2),axis=1) results in a Traceback (most recent call last): File "<ipython-input-264-85078aa26398>", line 1, in <module> t3 = np.concatenate((t1,t2),axis=1) IndexError: axis 1 out of bounds [0, 1) why does it report that axis 1 is out of bounds? Your title explains it - a 1d array does not have a 2nd axis! But having said that, on my system as on @Oliver W. s, it does not produce an error In [655]: np.concatenate((t1,t2),axis=1) Out[655]: array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17

Best Way To Concatenate Strings In PHP With Spaces In Between

大憨熊 提交于 2019-12-04 02:29:47
I need to concatenate an indeterminate number of strings, and I would like a space in between two adjoining strings. Like so a b c d e f . Also I do not want any leading or trailing spaces, what is the best way to do this in PHP? You mean $str = implode(' ', array('a', 'b', 'c', 'd', 'e', 'f')); ? $strings = array( " asd " , NULL, "", " dasd ", "Dasd ", "", "", NULL ); function isValid($v){ return empty($v) || !$v ? false : true; } $concatenated = trim( implode( " ", array_map( "trim", array_filter( $strings, "isValid" ) ) ) ); //"asd dasd Dasd" function concatenate() { $return = array();