string-split

How do I split a string on an empty line using .Split()?

有些话、适合烂在心里 提交于 2019-12-23 09:21:34
问题 For a class project I have to load a text file into a linked list. So far, I have been able to read from the file, but I am struggling to split it up into sections so that I can put it into the linked list. For example, I would like to split these items up at the empty lines: David Hunter No1 Admin John Smith No11 Sales Jane Appleby No5 Accounts I have tried String[] people = record.Split('\n'); but of course, this just splits it at every line. I have also tried: String[] people = record

Reversing words in a string JS without using built in function

不打扰是莪最后的温柔 提交于 2019-12-23 04:54:31
问题 Without using the split reverse and join functions, how would one do such a thing? The Problem Given: Reverse the words in a string Sample Input: "Hello World" Sample Output: "World Hello" <script> var newString = ""; var theString = prompt("Enter a Phrase that you would like to reverse (Ex. Hello world)"); newString = theString.split(" ").reverse().join(" ") document.write(newString); </script> 回答1: Another idea for reversing the words in a String is using a Stack data structure. Like so:

JavaScript string split by Regex results sub-strings include empty slices

南笙酒味 提交于 2019-12-20 06:26:09
问题 I've the following string splitting JavaScript code: var formula = "(field1 + field2) * (field5 % field2) / field3"; console.log(formula.split(/[+(-)% *\/]/)); And the result is out of expectation: ["", "field1", "", "", "field2", "", "", "", "", "field5", "", "", "field2", "", "", "", "field3"] What the desired result would be: ["field1", "field2", "field5", "field2", "field3"] I'm using Google Chrome 11 official release as the testing browser, please kindly advise what I'm doing wrong.

Empty check with string split

此生再无相见时 提交于 2019-12-20 05:38:42
问题 vector<string> SplitString (string aString,char *sep) { vector<string> vec; char * cstr,*val,*p; string str = aString; cstr = new char [str.size()+1]; strcpy (cstr, str.c_str()); p=strtok (cstr,sep); while(p!=NULL) { vec.push_back(p); p=strtok(NULL,sep); }delete[] cstr;return vec; } This is my code to string split. I sent the below string to split with separator '&' "f0=fname0&l0=lname0&f1=fname1&l1=lname1&f2=fname2&l2=lname2&f3=&l3=". I got result in the vector as below. f0=fname0 l0=lname0

How do I convert a string into an array?

本小妞迷上赌 提交于 2019-12-19 20:47:19
问题 I have a string like this string strings=" black door,white door,red door " Now I want to put this string into array. I use split myarray = strings.split(',') then array look like this: black,door,white,door,red,door. I want to put the string into the array after each occurance of comma not on the space. I want it like this in the array: black door,white door,red door. 回答1: if you have "black door,white door,red door" string then use only , as separator var result = "black door,white door,red

Currency values string split by comma

穿精又带淫゛_ 提交于 2019-12-19 17:45:59
问题 I have a String which contains formatted currency values like 45,890.00 and multiple values seperated by comma like 45,890.00,12,345.00,23,765.34,56,908.50 .. I want to extract and process all the currency values, but could not figure out the correct regular expression for this, This is what I have tried public static void main(String[] args) { String currencyValues = "45,890.00,12,345.00,23,765.34,56,908.50"; String regEx = "\\.[0-9]{2}[,]"; String[] results = currencyValues.split(regEx); /

Java StringTokenizer, empty null tokens

别等时光非礼了梦想. 提交于 2019-12-18 20:48:52
问题 I am trying to split a string into 29 tokens..... stringtokenizer won't return null tokens. I tried string.split, but I believe I am doing something wrong: String [] strings = line.split(",", 29); sample inputs: 10150,15:58,23:58,16:00,00:00,15:55,23:55,15:58,00:01,16:03,23:58,,,,,16:00,23:22,15:54,00:03,15:59,23:56,16:05,23:59,15:55,00:01,,,, 10155,,,,,,,,,,,07:30,13:27,07:25,13:45,,,,,,,,,,,07:13,14:37,08:01,15:23 10160,10:00,16:02,09:55,16:03,10:06,15:58,09:48,16:07,09:55,16:00,,,,,09:49

strsplit: undefined function for input type 'char'

*爱你&永不变心* 提交于 2019-12-18 03:16:23
问题 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,:)

Get values between curly braces c#

强颜欢笑 提交于 2019-12-17 20:07:49
问题 I never used regex before. I was abel to see similar questions in forum but not exactly what im looking for I have a string like following. need to get the values between curly braces Ex: "{name}{name@gmail.com}" And i Need to get the following splitted strings. name and name@gmail.com I tried the following and it gives me back the same string. string s = "{name}{name@gmail.com}"; string pattern = "({})"; string[] result = Regex.Split(s, pattern); 回答1: Is using regex a must? In this

Why does str.split not take keyword arguments?

纵然是瞬间 提交于 2019-12-17 16:18:58
问题 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. 回答1: 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