delimited-text

Convert comma separated list into JSON using Javascript

╄→尐↘猪︶ㄣ 提交于 2020-01-21 07:51:26
问题 How do you convert a comma separated list into json using Javascript / jQuery? e.g. Convert the following: var names = "Mark,Matthew,Luke,John,"; into: var jsonified = { names: [ {name: "Mark"}, {name: "Mattew"}, {name: "Luke"}, {name: "John"} ] }; 回答1: var jsonfied = { names: names.replace( /,$/, "" ).split(",").map(function(name) { return {name: name}; }) }; result of stringfying jsonfied: JSON.stringify( jsonfied ); { "names": [{ "name": "Mark" }, { "name": "Matthew" }, { "name": "Luke" },

How can I load in a pipe (|) delimited text file that has columns that sometimes contain line breaks?

落爺英雄遲暮 提交于 2020-01-06 06:24:27
问题 I have built an SSIS package that loads in several delimited text files into a SQL database. One of the files often contains line spaces in it, which breaks the standard data flow task of setting a flat file source and mapping to an ado.net destination since it thinks it is on a new line when it reaches a line break. The vendor sending over the files does not want to sent the file without any edits and can't do XML at this time. Is there any way to fix this? I was thinking of writing a small

mysql select odd number values in a column that includes delimiter separated values

你离开我真会死。 提交于 2020-01-06 05:31:09
问题 My next database table will be set up more optimally. Unfortunately this one was already set up where one column [data] contains checkbox array values that were saved the following way: value 1|~|value 1 value 2|~|value 2 value 3|~|value 3 Not optimal, I know. What I need is a mysql query that select only the values in [data] column in front of the |~|. Basically think I need to select the only odd values. Any help pointing me in the right direction is greatly appreciated. I tried an if

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

旧城冷巷雨未停 提交于 2019-12-28 07:17:04
问题 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); /

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

ε祈祈猫儿з 提交于 2019-12-28 07:16:10
问题 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); /

Get the nth string of text between 2 separator characters

天大地大妈咪最大 提交于 2019-12-25 03:59:16
问题 I have a long string of text delimited by a character (pipe character). I need to get the text between the 3rd and 4th pipes. Not sure how to go about this... Open to regex or non-regex, whichever is the most efficient. Especially open to extension method if none exist to be able to pass in: seperatorChar index 回答1: If string textBetween3rdAnd4thPipe = "zero|one|two|three|four".Split('|')[3]; doesn't do what you mean, you need to explain in more detail. 回答2: This regex will store the text

Multiple delimiters in column headers also separates the row values

為{幸葍}努か 提交于 2019-12-22 18:03:35
问题 I had a some issue about defining multiple seperator when reading a file. It is originally solved in my previous post reading-files-with-multiple-delimiter-in-column-headers-and-skipping-some-rows thanks to @piRsquared When I looked in detail to my real data I realized that some columns have .cd or .dvd extensions and when I applied the solution above they are also separated as a new column and the solution above started not to work! b.txt skip1 A1| A2 |A3 |A4# A5# A6 A7| A8 , A9 1,2,3,4,5.cd

Ruby : How can I detect/intelligently guess the delimiter used in a CSV file?

让人想犯罪 __ 提交于 2019-12-21 12:30:08
问题 I need to be able to figure out which delimiter is being used in a csv file (comma, space or semicolon) in my Ruby project. I know, there is a Sniffer class in Python in the csv module that can be used to guess a given file's delimiter. Is there anything similar to this in Ruby ? Any kind of help or idea is greatly appreciated. 回答1: Looks like the py implementation just checks a few dialects: excel or excel_tab. So, a simple implementation of something that just checks for "," or "\t" is: