string-concatenation

Efficiently repeat a character/string n times in Scala

守給你的承諾、 提交于 2019-11-28 07:08:19
I would like to do the following more efficiently: def repeatChar(char:Char, n: Int) = List.fill(n)(char).mkString def repeatString(char:String, n: Int) = List.fill(n)(char).mkString repeatChar('a',3) // res0: String = aaa repeatString("abc",3) // res0: String = abcabcabc Travis Brown For strings you can just write "abc" * 3 , which works via StringOps and uses a StringBuffer behind the scenes. For characters I think your solution is pretty reasonable, although char.toString * n is arguably clearer. Do you have any reason to suspect the List.fill version isn't efficient enough for your needs?

How do I concatenate strings in Entity Framework Query?

随声附和 提交于 2019-11-28 06:57:32
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 does not recognize the method 'System.String Join(System.String, System.Collections.Generic.IEnumerable`1

Concatenate multiple HTML text inputs with stored variable

只谈情不闲聊 提交于 2019-11-28 06:17:55
问题 I am trying to create a simple html form which asks for some details from a user and once this has been submitted will add the text to some predetermined text in a text box. Example of this... Text box 1 - Enter Name Text box 2 - Enter Age Text box 3 - Enter Location When this is submitted I would like this to be added preferably into a text box or even just output has text on an html page with other text already stored so the output would maybe be something like "Hello John, you are 25 years

why does a char + another char = a weird number

强颜欢笑 提交于 2019-11-28 05:55:42
问题 Here's the code snippet: public static void main (String[]arg) { char ca = 'a' ; char cb = 'b' ; System.out.println (ca + cb) ; } The output is: 195 Why is this the case? I would think that 'a' + 'b' would be either "ab" , "12" , or 3 . Whats going on here? 回答1: + of two char is arithmetic addition, not string concatenation. You have to do something like "" + ca + cb , or use String.valueOf and Character.toString methods to ensure that at least one of the operands of + is a String for the

JavaScript String concatenation behavior with null or undefined values

不问归期 提交于 2019-11-28 05:12:06
As you may know, in JavaScript '' + null = "null" and '' + undefined = "undefined" (in most browsers I can test: Firefox, Chrome and IE). I would like to know the origin of this oddity (what the heck was in the head on Brendan Eich?!) and if there is any aim for changing it in a future version of ECMA. It's indeed pretty frustrating having to do 'sthg' + (var || '') for concatenating Strings with variables and using a third party framework like Underscore or other for that is using a hammer for jelly nail pounding. Edit: To meet the criteria required by StackOverflow and clarify my question,

SQL Server 2000: Ideas for performing concatenation aggregation subquery

冷暖自知 提交于 2019-11-28 03:45:37
问题 i have a query that returns rows that i want, e.g. QuestionID QuestionTitle UpVotes DownVotes ========== ============= ======= ========= 2142075 Win32: Cre... 0 0 2232727 Win32: How... 2 0 1870139 Wondows Ae... 12 0 Now i want to have a column returned, that contains a comma separated list of " Authors " (e.g. original poster and editors). e.g.: QuestionID QuestionTitle UpVotes DownVotes Authors ========== ============= ======= ========= ========== 2142075 Win32: Cre... 0 0 Ian Boyd 2232727

How to concatenate strings in a Windows batch file?

青春壹個敷衍的年華 提交于 2019-11-28 03:32:05
I have a directory for which I want to list all the .doc files with a ; . I know the following batch command echos all the files: for /r %%i In (*.doc) DO echo %%i But now I want to put them all in a variable, add a ; in between and echo them all at once. How can I do that? set myvar="the list: " for /r %%i In (*.doc) DO <what?> echo %myvar% What about: @echo off set myvar="the list: " for /r %%i in (*.doc) DO call :concat %%i echo %myvar% goto :eof :concat set myvar=%myvar% %1; goto :eof Based on Rubens' solution, you need to enable Delayed Expansion of env variables (type "help setlocal" or

Concatenating string and integer in python

那年仲夏 提交于 2019-11-28 02:58:21
In python say you have s = "string" i = 0 print s+i will give you error so you write print s+str(i) to not get error. I think this is quite a clumsy way to handle int and string concatenation. Even Java does not need explicit casting to String to do this sort of concatenation. Is there a better way to do this sort of concatenation i.e without explicit casting in Python? Modern string formatting: "{} and {}".format("string", 1) No string formatting: >> print 'Foo',0 Foo 0 String formatting, using the new-style .format() method (with the defaults .format() provides): '{}{}'.format(s, i) Or the

Best practices/performance: mixing StringBuilder.append with String.concat

两盒软妹~` 提交于 2019-11-28 02:46:10
I'm trying to understand what the best practice is and why for concatenating string literals and variables for different cases. For instance, if I have code like this StringBuilder sb = new StringBuilder("AAAAAAAAAAAAA") .append(B_String).append("CCCCCCCCCCC").append(D_String) .append("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE") .append("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); Is this the way to do it? From this post , I noticed that the + operator on Strings creates a new instance of StringBuilder, concatenates the operands, and returns a String conversion

Group subarrays by one column, make comma-separated values from other column within groups

南楼画角 提交于 2019-11-28 02:24:38
I have a array that looks like this: $array = [ ["444", "0081"], ["449", "0081"], ["451", "0081"], ["455", "2100"], ["469", "2100"] ]; I need to group as a new array that looks like: array ( 0 => array ( 0 => '444,449,451', 1 => '0081', ), 1 => array ( 0 => '455,469', 1 => '2100', ), ) I'd tried many scripts, but with no success. function _group_by($array, $key) { $return = array(); foreach($array as $val) { $return[$val[$key]][] = $val; } return $return; } $newArray = _group_by($array, 1); // (NO SUCCESS) Giedrius There should be more elegant solutions, but simplest one I can think of would