delimiter

Cut string after first occurrence of a character

ε祈祈猫儿з 提交于 2019-12-04 05:02:55
I have strings like 'keepme:cutme' or 'string-without-separator' which should become respectively 'keepme' and 'string-without-separator'. Can this be done in PostgreSQL? I tried: select substring('first:last' from '.+:') But this leaves the : in and won't work if there is no : in the string. Erwin Brandstetter Use split_part() : SELECT split_part('first:last', ':', 1) AS first_part Returns the whole string if the delimiter is not there. And it's simple to get the 2nd or 3rd part etc. Substantially faster than functions using regular expression matching. And since we have a fixed delimiter we

Split string based on regex but keep delimiters

隐身守侯 提交于 2019-12-04 05:01:27
问题 I'm trying to split a string using a variety of characters as delimiters and also keep those delimiters in their own array index. For example say I want to split the string: if (x>1) return x * fact(x-1); using '(', '>', ')', '*', '-', ';' and '\s' as delimiters. I want the output to be the following string array: {"if", "(", "x", ">", "1", ")", "return", "x", "*", "fact", "(", "x", "-", "1", ")", ";"} The regex I'm using so far is split("(?=(\\w+(?=[\\s\\+\\-\\*/<(<=)>(>=)(==)(!=)=;,\\.\"\\(

PHP - Best approach to detect CSV delimiter

守給你的承諾、 提交于 2019-12-04 04:50:46
I have seen multiple threads about what the best solution to auto detect the delimiter for an incoming CSV. Most of them are functions of length between 20 - 30 lines, multiple loops pre-determined list of delimiters, reading the first 5 lines and matching counts e.t.c e.t.c Here is 1 example I have just implemented this procedure, with a few modifications. Works brilliantly. THEN I found the following code: private function DetectDelimiter($fh) { $data_1 = null; $data_2 = null; $delimiter = self::$delim_list['comma']; foreach(self::$delim_list as $key=>$value) { $data_1 = fgetcsv($fh, 4096,

Implementing `strtok` whose delimiter has more than one character

拜拜、爱过 提交于 2019-12-04 02:11:26
问题 Code snippet: char str[] = "String1::String2:String3:String4::String5"; char *deli = "::"; char *token = strtok(str,deli); while(token != NULL) { printf("Token= \"%s\"\n", token); token=strtok(NULL,deli); } The above code snippet produces the output: Token="String1" Token="String2" Token="String3" Token="String4" Token="String5" but I want the output to be: Token="String1" Token="String2:String3:String4" Token="String5" I know that I am not getting the expected output because each character

Multiple delimiters in single CSV file

寵の児 提交于 2019-12-04 01:39:12
问题 I have a CSV, which has got three different delimiters namely, '|', ',' and ';' between different columns. How can I using Python parse this CSV ? My data is like below : 2017-01-24|05:19:30+0000|TRANSACTIONDelim_secondUSER_LOGINDelim_firstCONSUMERIDDelim_secondc4115f53-3798-4c9e-9bfd-506c842aff96Delim_firstTRANSACTIONDATEDelim_second17-01-24 05:19:30Delim_firstCHANNELIDDelim_secondDelim_firstSHOWIDDelim_secondDelim_firstEPISODEIDDelim_secondDelim_firstBUSINESSUNITDelim_secondnullDelim

C# StreamReader, “ReadLine” For Custom Delimiters

不羁岁月 提交于 2019-12-04 00:21:09
What is the best way to have the functionality of the StreamReader.ReadLine() method, but with custom (String) delimiters? I'd like to do something like: String text; while((text = myStreamReader.ReadUntil("my_delim")) != null) { Console.WriteLine(text); } I attempted to make my own using Peek() and StringBuilder , but it's too inefficient. I'm looking for suggestions or possibly an open-source solution. Thanks. Edit I should have clarified this earlier...I have seen this answer , however, I'd prefer not to read the entire file into memory. I figured I would post my own solution. It seems to

D3 remove comma delimiters for thousands

不羁岁月 提交于 2019-12-03 22:22:10
I have a .json with 3 columns where one of them is 'Year'. The column contains only years. No dates!. When I am graphing it on the 'x' axis the years come out with a comma delimiter for thousands. So in the .json the date is this format :"Year":1990 and on the 'x' axis it comes out like that 1,990 I have been trying to figure out how to parse the year but I have no luck so far. I have tried the following: var parseDate = d3.time.format("%y").parse var x = d3.time.scale() .range([0, width]); //further down d3.json("waterData.json", function(error, json) { // Attach Data var data = json.data; //

Error near 'DELIMITER $$'

邮差的信 提交于 2019-12-03 17:22:46
when I change Delimeter from mysql console or MySQL Workbench I do not get any error, but when I embed the same code in ruby on rails I get error mysql> DELIMITER $$ mysql> gives no error. but ActiveRecord::Base.connection.execute(%Q{ DELIMITER $$ }) gives: ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$' at line 1: DELIMITER is actually a MySQL command line setting, not SQL: http://dev.mysql.com/doc/refman/5.0/en/mysql-commands.html . That means

Echo changes my tabs to spaces

 ̄綄美尐妖づ 提交于 2019-12-03 16:06:51
问题 I'm taking the following structure from around the net as a basic example of how to read from a file in BASH: cat inputfile.txt | while read line; do echo $line; done My inputfile.txt is tab-delimited, though, and the lines that come out of the above command are space-delimited. This is causing me problems in my actual application, which is of course more complex than the above: I want to take the line, generate some new stuff based on it, and then output the original line plus the new stuff

Backslash zero delimiter '\0'

杀马特。学长 韩版系。学妹 提交于 2019-12-03 11:11:34
问题 I have seen '\0' to be used as a delimiter in mixed binary files (UTF8 strings + binary data). Could anyone explain what '\0' means or point to a good place to study? 回答1: It's the null character; more info in this Wikipedia article. 回答2: The two-character \0 representation is used in C source code to represent the NUL character, which is the (single) character with ASCII value 0. The NUL character is used in C style character strings to indicate where the end of the string is. For example,