delimiter

C++ spliting string by delimiters and keeping the delimiters in result

蓝咒 提交于 2020-01-22 12:54:08
问题 I'm looking for a way to split string by multiple delimiters using regex in C++ but without losing the delimiters in output, keeping the delimiters with splitted parts in order, for example: Input aaa,bbb.ccc,ddd-eee; Output aaa , bbb . ccc , ddd - eee ; I've found some solutions for this but all in C# or java, looking for some C++ solution, preferably without using Boost. 回答1: You could build your solution on top of the example for regex_iterator. If, for example, you know your delimiters

Split string at last (or fourth) occurence of “.” delimiter

我怕爱的太早我们不能终老 提交于 2020-01-17 03:49:19
问题 I like to delimit the string as follow Given the following String : Column 1 10.80.111.199.1345 127.0.0.1.3279 I will like to delimit numbers after the last ".", which will get the follow output Column 1 Column 2 10.1.12.5 1345 127.0.0.1 3279 I know excel has the delimitor function which allows me to delimit with specific symbol or through the fixed width. It does not seems to work for fixed width. Is there any alternatives, rather than delimited with "." can concating back the strings on

How to prevent storing of text coming after special characters — in arraylist in java

眉间皱痕 提交于 2020-01-17 01:22:12
问题 I am reading a pl/sql code from a text file and storing all words of it into array list from below code : Scanner in1 = new Scanner(file1); ArrayList<String> Code1 = new ArrayList<String>(); in1.useDelimiter("/\\*[^*]*\\*+(?:[^/*][^*]*\\*+)*/|[\\p{javaWhitespace}\\.|,]+"); while (in1.hasNext()) { Code1.add(in1.next().toLowerCase()); } Everything is working fine but i am facing issue whenever there is a comments section in code written in after special character -- Like below: select * from

R Question - Trying to use separate to split data with a non-constant delimiter

流过昼夜 提交于 2020-01-16 09:02:28
问题 One of the variables is participant age groups, an example of one of the records is shown below, 0::Adult 18+||1:: Adult 18+||2::Adult 18+||3::Child 0-11 How do you best split this out so that it will give Adult 18 + with the result of 3 and Child 0-11 with 1? I tried using separate, but as the delimiter is not constant, it was omitting a lot of the records. Any suggestions would be helpful, thank you! As this is my first post, let me know if I need to add more information. 回答1: Here is one

Java Scanner Headache

半城伤御伤魂 提交于 2020-01-15 11:18:20
问题 I have a text file which looks like: name1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 name2 1 0 1 0 1 0 0 1 1 0 0 0 0 0 1 i.e., a plaintext label followed by a few rows with 1/0 separated by spaces. The number of rows of 1/0 is variable, but each row between any two particular labels should have the same number of 1/0s (though might potentially not). How do I grab each name+rows chunk with a scanner? Is there any elegant way to enforce the consistency on the number of rows (and provide some sort of

google-bigquery Error while specifying pipe delimiter in bq load command on windows

ぃ、小莉子 提交于 2020-01-15 09:50:07
问题 I am trying to load a PIPE delimited file and running bq load command from windows platform. It is not accepting pipe delimiter in the command. E.g. I am trying to use -F operator to specify the delimiter and could specify space delimiter but it stops working when I specify pipe delimiter. C:\Windows>bq load -F" " "cmdwh_bq_prod.testtabPIPE" "c:\temp\testPIPE.txt" PlatformVersion:int64,AnalyticsSessionID:int64,OutletGroup:string Upload complete. ..... rest of the processing...... ..... rest

split equation string by multiple delimiters in javascript and keep delimiters then put string back together

我与影子孤独终老i 提交于 2020-01-14 19:51:10
问题 I have an equation I want to split by using operators + , - , / , * as the delimiters. Then I want to change one item and put the equation back together. For example an equation could be s="5*3+8-somevariablename/6"; I was thinking I could use regular expressions to break the equation apart. re=/[\+|\-|\/|\*]/g var elements=s.split(re); Then I would change an element and put it back together. But I have no way to put it back together unless I can somehow keep track of each delimiter and when

Changing the scanf() delimiter

随声附和 提交于 2020-01-13 19:08:39
问题 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); } 回答1: Consider this (C99) code: #include <stdio.h> int main(void) { char buffer[256]; while (scanf("%255[^\n]", buffer) == 1) printf("Found <<%s>>\n",

Calculate average of each column in a file

旧城冷巷雨未停 提交于 2020-01-13 11:30:10
问题 I have a text file with n number of rows (separated by commas) and columns and I want to find average of each column, excluding empty field. A sample input looks like: 1,2,3 4,,6 ,7, The desired output is: 2.5, 4.5, 4.5 I tried with awk -F',' '{ for(i=1;i<=NF;i++) sum[i]=sum[i]+$i;if(max < NF)max=NF;};END { for(j=1;j<=max;j++) printf "%d\t",sum[j]/max;}' input But it treats consecutive delimiters as one and mixing columns. Any help is much appreciated. 回答1: You can use this one-liner: $ awk

New line as a delimeter of FOR loop

﹥>﹥吖頭↗ 提交于 2020-01-11 10:22:32
问题 I am new to batch script, and I am trying to parse a file that has key value (kind) of pairs delimited by new line. For example: the value of abc 1234 the value of def 5678 the value of ghi 9876 I would like to read this file using new line as delimited so that I can access the values. Something like for /f "tokens=1,2,3 delims='\n'" %%i in ('findstr /C:the value of abc 'filepath') do echo %%j 回答1: You can't set 'new line' as delimiter. Try this: @echo off &setlocal for /f "tokens=1*delims=:"