delimiter

Java parsing string

孤人 提交于 2019-12-06 00:31:27
I'm looking to parse the following string in java <some lines here> Key1:thingIWantToKnow Key2:otherThing Key3:bla Key4:bla Key5:bla <(possibly) more lines here> All lines end with a newline (\n) character. I'm looking to store the value pair once I find the key's I'm care about. If a Map is what you want: Map<String, String> keyValueMap = new HashMap<String,String>(); String[] lines = input.split("\n"); if (lines == null) { //Compensate for strange JDK semantics lines = new String[] { input }; } for (String line : lines) { if (!line.contains(":")) { //Skip lines that don't contain key-value

PHP preg_split with two delimiters unless a delimiter is within quotes

不打扰是莪最后的温柔 提交于 2019-12-06 00:28:26
Further on from my previous question about preg_split which was answers super fast, thanks to nick; I would really like to extend the scenario to no split the string when a delimiter is within quotes. For example: If I have the string foo = bar AND bar=foo OR foobar="foo bar" , I'd wish to split the sting on every space or = character but include the = character in the returned array (which works great currently), but I don't want to split the string either of the delimiters are within quotes. I've got this so far: <!doctype html> <?php $string = 'foo = bar AND bar=foo'; $array = preg_split('/

Cut string after first occurrence of a character

邮差的信 提交于 2019-12-05 23:20:54
问题 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. 回答1: 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

Changing the scanf() delimiter

巧了我就是萌 提交于 2019-12-05 22:33:00
My objective is to change the delimiter of scanf to " \n ". I tried using scanf("%[^\n]s",sen); and works fine for single inputs. But when i put the same line inside a for loop for multiple sentences it gives me garbage values. Does anyone know why? Here's my code: char sen[20]; for (i=0;i<2;i++) { scanf("%[^\n]s",sen); printf("%s\n",sen); } Consider this (C99) code: #include <stdio.h> int main(void) { char buffer[256]; while (scanf("%255[^\n]", buffer) == 1) printf("Found <<%s>>\n", buffer); int c; if ((c = getchar()) != EOF) printf("Failed on character %d (%c)\n", c, c); return(0); } When I

JS RegEx to match all characters (including newline) between two strings but without the two strings?

最后都变了- 提交于 2019-12-05 21:33:40
Example Text: <div id="not-wanted"> no no no </div> <div id="wanted">I want only this text </div> no no no no no <div id="not-wanted"> no no no </div> <div id="wanted">no no no no</div> <div id="wanted"> no no </div> Should deliver: I want only this text Or better: I want only this text Unfortunately, my solution catches the 2 delimitation strings also: $('#put').append(/<div id="wanted">[^<>]*<\/div>/.exec(strg)[0]); ==> <div id="wanted">I want only this text </div> Online example http://regex101.com/r/rF7jR9 Question What regular expression for Java Script can deliver the characters between

Replacing delimiter characters in file path

余生颓废 提交于 2019-12-05 14:24:02
I'm developing a C# web application in VS 2008. I let the user select an input file and then I store the file path in a string variable. However, it stores this path as "C:\\folder\\..." . So my question is how do I convert this file path into single "\"? Thank you guys for all your helps! Please forgive me as I am a newbie to ASP.NET development. This is more of my code in context. First I want to see if the directory exists. I guess I don't have to check this if I check if the file exists. But this should still work right? And currently my "path" string variable is not showing up the way I

D3 remove comma delimiters for thousands

◇◆丶佛笑我妖孽 提交于 2019-12-05 09:39:33
问题 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]); /

Error near 'DELIMITER $$'

萝らか妹 提交于 2019-12-05 02:30:47
问题 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: 回答1: DELIMITER is actually a

Java CSV parser with string separator (multi-character)

耗尽温柔 提交于 2019-12-05 01:08:43
Is there any Java open source library that supports multi-character (i.e., String with length > 1) separators (delimiters) for CSV? By definition, CSV = Comma-Separated Values data with a single character (',') as the delimiter. However, many other single-character alternatives exist (e.g., tab), making CSV to stand for "Character-Separated Values" data (essentially, DSV: Delimiter-Separated Values data). Main Java open source libraries for CSV (e.g., OpenCSV ) support virtually any character as the delimiter, but not string (multi-character) delimiters. So, for data separated with strings

Replacing one character with another in a string

房东的猫 提交于 2019-12-04 22:32:37
I have a data like below: A:B:C:D and I want to replace the C with data (say, Z ) so that it may look like A:B:Z:D How can I do it? =SUBSTITUTE(A1,"C","Z") Although I wasn't clear on whether you wanted G or Z , you mentioned G but your example output shows Z . jrad If you have A:B:C:D in cell A1, then this works: =CONCATENATE(MID(A1, 1, SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + SEARCH(":", A1)), "Z", MID(MID(MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1), SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + 1, LEN(MID(A1,