delimiter

Can you use a trailing comma in a JSON object?

99封情书 提交于 2019-11-26 03:22:10
问题 When manually generating a JSON object or array, it\'s often easier to leave a trailing comma on the last item in the object or array. For example, code to output from an array of strings might look like (in a C++ like pseudocode): s.append(\"[\"); for (i = 0; i < 5; ++i) { s.appendF(\"\\\"%d\\\",\", i); } s.append(\"]\"); giving you a string like [0,1,2,3,4,5,] Is this allowed? 回答1: Unfortunately the JSON specification does not allow a trailing comma. There are a few browsers that will allow

C# List<string> to string with delimiter

北城余情 提交于 2019-11-26 03:02:16
问题 Is there a function in C# to quickly convert some collection to string and separate values with delimiter? For example: List<string> names --> string names_together = \"John, Anna, Monica\" 回答1: You can use String.Join. If you have a List<string> then you can call ToArray first: List<string> names = new List<string>() { "John", "Anna", "Monica" }; var result = String.Join(", ", names.ToArray()); In .NET 4 you don't need the ToArray anymore, since there is an overload of String.Join that takes

Split a string into an array of strings based on a delimiter

倾然丶 夕夏残阳落幕 提交于 2019-11-26 02:55:48
问题 I\'m trying to find a Delphi function that will split an input string into an array of strings based on a delimiter. I\'ve found a lot on Google, but all seem to have their own issues and I haven\'t been able to get any of them to work. I just need to split a string like: \"word:doc,txt,docx\" into an array based on \':\'. The result would be [\'word\', \'doc,txt,docx\'] . Does anyone have a function that they know works? Thank you 回答1: you can use the TStrings.DelimitedText property for

Escaping separator within double quotes, in awk

夙愿已清 提交于 2019-11-26 02:38:23
问题 I am using awk to parse my data with \",\" as separator as the input is a csv file. However, there are \",\" within the data which is escaped by double quotes (\"...\"). Example filed1,filed2,field3,\"field4,FOO,BAR\",field5 How can i ignore the comma \",\" within the the double quote so that I can parse the output correctly using awk? I know we can do this in excel, but how do we do it in awk? 回答1: It's easy, with GNU awk 4 : zsh-4.3.12[t]% awk '{ for (i = 0; ++i <= NF;) printf "field %d =>

Python split() without removing the delimiter [duplicate]

六眼飞鱼酱① 提交于 2019-11-26 02:24:48
问题 This question already has answers here : In Python, how do I split a string and keep the separators? (11 answers) Closed 6 years ago . This code almost does what I need it to.. for line in all_lines: s = line.split(\'>\') Except it removes all the \'>\' delimiters. So, <html><head> Turns into [\'<html\',\'<head\'] Is there a way to use the split() method but keep the delimiter, instead of removing it? With these results.. [\'<html>\',\'<head>\'] 回答1: d = ">" for line in all_lines: s = [e+d

changing the delimiter for cin (c++)

◇◆丶佛笑我妖孽 提交于 2019-11-26 01:15:54
问题 I\'ve redirected \"cin\" to read from a file stream cin.rdbug(inF.rdbug()) When I use the extraction operator it reads until it reaches a white space character. Is it possible to use another delimiter? I went through the api in cplusplus.com, but didn\'t find anything. 回答1: It is possible to change the inter-word delimiter for cin or any other std::istream, using std::ios_base::imbue to add a custom ctype facet. If you are reading a file in the style of /etc/passwd, the following program will

Capturing output of find . -print0 into a bash array

浪尽此生 提交于 2019-11-26 01:14:08
问题 Using find . -print0 seems to be the only safe way of obtaining a list of files in bash due to the possibility of filenames containing spaces, newlines, quotation marks etc. However, I\'m having a hard time actually making find\'s output useful within bash or with other command line utilities. The only way I have managed to make use of the output is by piping it to perl, and changing perl\'s IFS to null: find . -print0 | perl -e \'$/=\"\\0\"; @files=<>; print $#files;\' This example prints

Split comma separated column data into additional columns

回眸只為那壹抹淺笑 提交于 2019-11-26 00:59:31
问题 I have comma separated data in a column: Column ------- a,b,c,d I want to split the comma separated data into multiple columns to get this output: Column1 Column2 Column3 Column4 ------- ------- ------- ------- a b c d How can this be achieved? 回答1: If the number of fields in the CSV is constant then you could do something like this: select a[1], a[2], a[3], a[4] from ( select regexp_split_to_array('a,b,c,d', ',') ) as dt(a) For example: => select a[1], a[2], a[3], a[4] from (select regexp

Is it possible to use AngularJS with the Jinja2 template engine?

元气小坏坏 提交于 2019-11-26 00:37:47
问题 I have a Flask site and I want to use the AngularJS JavaScript framework. Unfortunately, it seems as if the delimiters overlap. How do I use Angular with Jinja2 if both rely on double curly braces ( {{ expr }} )? Is it even possible? 回答1: You have some options. 1) Change the delimiter notation for Angular: var app = angular.module('Application', []); app.config(['$interpolateProvider', function($interpolateProvider) { $interpolateProvider.startSymbol('{a'); $interpolateProvider.endSymbol('a}'

Delimiters in MySQL

匆匆过客 提交于 2019-11-25 22:59:49
问题 I often see people are using Delimiters. I tried myself to find out what are delimiters and what is their purpose. After 20 minutes of googling, I was not able to find an answer which satisfies me. So, my question is now: What are delimiters and when should I use them? 回答1: Delimiters other than the default ; are typically used when defining functions, stored procedures, and triggers wherein you must define multiple statements. You define a different delimiter like $$ which is used to define