split

How to use boost split to split a string and ignore empty values?

冷暖自知 提交于 2021-02-05 23:43:52
问题 I am using boost::split to parse a data file. The data file contains lines such as the following. data.txt 1:1~15 ASTKGPSVFPLAPSS SVFPLAPSS -12.6 98.3 The white space between the items are tabs. The code I have to split the above line is as follows. std::string buf; /*Assign the line from the file to buf*/ std::vector<std::string> dataLine; boost::split( dataLine, buf , boost::is_any_of("\t "), boost::token_compress_on); //Split data line cout << dataLine.size() << endl; For the above line of

Python: chemical elements counter

放肆的年华 提交于 2021-02-05 12:29:07
问题 I want to get the elements for a given mixture. For examples, for a mixsture of Air (O2 and N2) and Hexane (C6H14) given by the dict with their respectives mole numbers mix = {'O2': 1, 'N2': 3.76, 'C6H14': 0.01} I want to get the following: {O: 2, N: 7.52, C:0.06, H: 0.14} Another example: mix = {'C6H14': 1, 'C9H20': 1} must yields {H: 34, C: 15} enter code here The sequence of the dict it's not important. I was trying with the re.split, but I don't get any progress. If anyone can help me I

Removing item in list during loop

痞子三分冷 提交于 2021-02-05 12:26:02
问题 I have the code below. I'm trying to remove two strings from lists predict strings and test strings if one of them has been found in the other. The issue is that I have to split up each of them and check if there is a "portion" of one string inside the other. If there is then I just say there is a match and then delete both strings from the list so they are no longer iterated over. ValueError: list.remove(x): x not in list I get the above error though and I am assuming this is because I can't

split columns into multiple columns

故事扮演 提交于 2021-02-05 12:18:41
问题 i have been struggled with how to split multiple columns into multiple columns using R but with no result, i have tried many tricks on Stackoverflow and it doesn't work. here is my probleme : reactions__001 reactions__002 reactions__003 25 Like 23 Love 15 Like 5 Love 3 Haha 20 Haha 3 Sad 2 Angry now what i am looking for is to split this data frame like this one Like Love Haha Sad Angry 25 23 0 0 0 15 5 3 0 0 0 0 20 3 2 i have tried the str_split_fixed(df$reactions__001, " ", 2) but it gives

Splitting a space separated string

大憨熊 提交于 2021-02-05 09:36:55
问题 String numbers = "5 1 5 1"; So, is it: String [] splitNumbers = numbers.split(); or: String [] splitNumbers = numbers.split("\s+"); Looking for: ["5","1","5","1"] Any idea why neither of the .split lines will work? I tried reading answers about the regex, but I'm not getting anywhere. 回答1: You must escape the regex with an additional \ since \ denotes the escape character: public static void main(String[] args) { String numbers = "5 1 5 1"; String[] tokens = numbers.split("\\s+"); for(String

how to split ObservableCollection

放肆的年华 提交于 2021-02-05 08:15:59
问题 i have ObservableCollection with 100 records. now i want to get split that collection in 10 new collection each having 10 records. it means 1 collection = 100 records (10 collection = 10 records) = 1 collection any help will be apricited. 回答1: Using Linq var collection=new ObservableCollection<int>(Enumerable.Range(1,100)); collection.Aggregate(new ObservableCollection<ObservableCollection<int>>(), (x,i)=>{ if (!x.Any() || x.Last().Count()==10) x.Add(new ObservableCollection<int>()); x.Last()

how to split a string in a column field value of a table to multiple rows in select query in postgresql

荒凉一梦 提交于 2021-02-05 07:54:09
问题 table1 ID ITEM ----------------------- 1 a|b|c 2 x|y|z 3 Q||S 4 |||| 5 J|K|Y|U I want to insert above ITEM to table2 as following manner table2 SLNO ID ITEMS ------------------------ 1 1 a 2 1 b 3 1 c 4 2 x 5 2 y 6 2 z 7 3 Q 8 3 S 9 5 J 10 5 K 11 5 Y 12 5 U so i have used INSERT INTO table2("ID","ITEMS")SELECT ID,split_part("ITEM", '|',1) AS ITEMS FROM table1 the problem is split_part() need to specify a postion index,so it only split and shows first positions charaters means, ID ITEMS ------

Using str.split for pandas dataframe values based on parentheses location

此生再无相见时 提交于 2021-02-05 06:47:05
问题 Let's say I have the following dataframe series df['Name'] column: Name 'Jerry' 'Adam (and family)' 'Paul and Hellen (and family):\n' 'John and Peter (and family):/n' How would I remove all the contents in Name after the first parentheses? df['Name']= df['Name'].str.split("'(").str[0] doesn't seem to work and I don't understand why? The output I want is Name 'Jerry' 'Adam' 'Paul and Hellen' 'John and Peter' so everything after the parentheses is deleted. 回答1: Solution with split - is

Latin Regex with symbols

帅比萌擦擦* 提交于 2021-02-05 05:51:27
问题 I need split a text and get only words, numbers and hyphenated composed-words. I need to get latin words also, then I used \p{L} , which gives me é, ú ü ã, and so forth. The example is: String myText = "Some latin text with symbols, ? 987 (A la pointe sud-est de l'île se dresse la cathédrale Notre-Dame qui fut lors de son achèvement en 1330 l'une des plus grandes cathédrales d'occident) : ! @ # $ % ^& * ( ) + - _ #$% " ' : ; > < / \ | , here some is wrong… * + () e -" Pattern pattern =

Latin Regex with symbols

爷,独闯天下 提交于 2021-02-05 05:51:06
问题 I need split a text and get only words, numbers and hyphenated composed-words. I need to get latin words also, then I used \p{L} , which gives me é, ú ü ã, and so forth. The example is: String myText = "Some latin text with symbols, ? 987 (A la pointe sud-est de l'île se dresse la cathédrale Notre-Dame qui fut lors de son achèvement en 1330 l'une des plus grandes cathédrales d'occident) : ! @ # $ % ^& * ( ) + - _ #$% " ' : ; > < / \ | , here some is wrong… * + () e -" Pattern pattern =