string-split

Using sed to split a string with a delimiter

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 20:51:11
I have a string in the following format: string1:string2:string3:string4:string5 I'm trying to use sed to split the string on : and print each sub-string on a new line. Here is what I'm doing: cat ~/Desktop/myfile.txt | sed s/:/\\n/ This prints: string1 string2:string3:string4:string5 How can I get it to split on each delimiter? To split a string with a delimiter with GNU sed you say: sed 's/delimiter/\n/g' # GNU sed For example, to split using : as a delimiter: $ sed 's/:/\n/g' <<< "he:llo:you" he llo you Or with a non-GNU sed: $ sed $'s/:/\\\n/g' <<< "he:llo:you" he llo you In this

LINQ to Entities: Why can't I use Split method as condition?

半世苍凉 提交于 2019-11-29 15:03:40
I have the following LINQ query: var aKeyword = "ACT"; var results = from a in db.Activities where a.Keywords.Split(',').Contains(aKeyword) == true select a; Keywords is a comma delimited field. Everytime I run this query I get the following error: "LINQ to Entities does not recognize the method 'Boolean Contains[String](System.Collections.Generic.IEnumerable`1[System.String], System.String)' method, and this method cannot be translated into a store expression." What is the alternative for what I am trying to do? In response to your performance considerations on a big dataset: You are going to

strsplit: undefined function for input type 'char'

流过昼夜 提交于 2019-11-29 01:32:39
I have a <20x1> cell array and each of them stores some data in the form of a string (as it appears to me!!!). I want to access each element of the cell as an individual string and split is in words. The cell array I have is <20x1> cell array and to access each element as a cell I am using a for loop. for i=1:20 line=newline{i} end It shows me a all the elements within the array. Now since line is a string, I apply strsplit function to retrieve the words in the string. for i=1:20 words(i,:)=strsplit(line) end This gives me an error message : ??? Undefined function or method 'strsplit' for

How to split a string in bash delimited by tab

橙三吉。 提交于 2019-11-28 23:51:55
问题 I'm trying to split a tab delimitted field in bash. I am aware of this answer: how to split a string in shell and get the last field But that does not answer for a tab character. I want to do get the part of a string before the tab character, so I'm doing this: x=`head -1 my-file.txt` echo ${x%\t*} But the \t is matching on the letter 't' and not on a tab. What is the best way to do this? Thanks 回答1: If your file look something like this (with tab as separator): 1st-field 2nd-field you can

Using sed to split a string with a delimiter

若如初见. 提交于 2019-11-28 16:38:56
问题 I have a string in the following format: string1:string2:string3:string4:string5 I'm trying to use sed to split the string on : and print each sub-string on a new line. Here is what I'm doing: cat ~/Desktop/myfile.txt | sed s/:/\\n/ This prints: string1 string2:string3:string4:string5 How can I get it to split on each delimiter? 回答1: To split a string with a delimiter with GNU sed you say: sed 's/delimiter/\n/g' # GNU sed For example, to split using : as a delimiter: $ sed 's/:/\n/g' <<< "he

why a “” in the 0th index of an array on perfoaming a split() w/o delimiters?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 13:09:00
public static void main(String[] args) { // TODO Auto-generated method stub String str="aaabbddaabbcc"; String[] str2=str.split(""); String pointer=str2[0]; int count=0; String finalStr=""; for(String str132:str2) { if(str132.equalsIgnoreCase(pointer)) { ++count; } else { finalStr+=str132+count; count=0; pointer=str132; ++count; } } System.out.println(finalStr); } On performing a str.split("") , why am I getting a "" in the 0th index of the str2 array? why am i getting a "" in the 0th index of the str2 array? Because the delimiter you use has matched here: aaaabbddaabbcc ^ Since .split()

LINQ to Entities: Why can't I use Split method as condition?

徘徊边缘 提交于 2019-11-28 08:43:44
问题 I have the following LINQ query: var aKeyword = "ACT"; var results = from a in db.Activities where a.Keywords.Split(',').Contains(aKeyword) == true select a; Keywords is a comma delimited field. Everytime I run this query I get the following error: "LINQ to Entities does not recognize the method 'Boolean Contains[String](System.Collections.Generic.IEnumerable`1[System.String], System.String)' method, and this method cannot be translated into a store expression." What is the alternative for

Why does str.split not take keyword arguments?

有些话、适合烂在心里 提交于 2019-11-27 21:51:37
I came across this - in my view - strange behaviour: "a b c".split(maxsplit=1) TypeError: split() takes no keyword arguments Why does str.split() not take keyword arguments, even though it would make sense? I found this behavior both in Python2 and Python3. See this bug and its superseder . str.split() is a native function in CPython, and as such exhibits the behavior described here : CPython implementation detail: An implementation may provide built-in functions whose positional parameters do not have names, even if they are ‘named’ for the purpose of documentation, and which therefore cannot

Split a string every 5 characters

前提是你 提交于 2019-11-27 13:09:05
Suppose I have a long string: "XOVEWVJIEWNIGOIWENVOIWEWVWEW" How do I split this to get every 5 characters followed by a space? "XOVEW VJIEW NIGOI WENVO IWEWV WEW" Note that the last one is shorter. I can do a loop where I constantly count and build a new string character by character but surely there must be something better no? Using regular expressions: gsub("(.{5})", "\\1 ", "XOVEWVJIEWNIGOIWENVOIWEWVWEW") # [1] "XOVEW VJIEW NIGOI WENVO IWEWV WEW" Using sapply > string <- "XOVEWVJIEWNIGOIWENVOIWEWVWEW" > sapply(seq(from=1, to=nchar(string), by=5), function(i) substr(string, i, i+4)) [1]

getting “comma-separated list near 'xx.yy' invalid” with dbms_utility.comma_to_table

我们两清 提交于 2019-11-27 09:10:27
I have string like this: str:='ac_Abc.88,ac_Abc.99,ac_Abc.77'. I need to get first element after splitting with comma(,). So im using using like this: str VARCHAR2(500); dbms_utility.comma_to_table ( list => regexp_replace(str,'(^|,)','\1') , tablen => l_count , tab => l_array ); I'm getting following error: ORA-20001: comma-separated list invalid near bc.88 ORA-06512: at "SYS.DBMS_UTILITY", line 239 ORA-06512: at "SYS.DBMS_UTILITY", line 272 But if i have string like this, str:='ac_Abc88,ac_Abc99,ac_Abc77', the same method working fine and giving me expected results. So i guess there is