Ahhh, yes! Forgot all about that one. Good one, Nikhil ! Personally, though, if you have hundreds of lines of such sample input, it might be much slower to use that overload because of the obvious extra work involved.
On Feb 18, 2:30 pm, nikhil gaitonde <[email protected]> wrote: > Hi, > > Whenever you split the string based on any characters it will give even > empty entries. > So in case you have more than one spaces then it will be more than your > expected size (7 in this case) > Please include the second parameter as given below. > Hope this should help. > string [] arrs = s.Split(arr, StringSplitOptions.RemoveEmptyEntries); > > Regards, > > Nikhil > > > > On Wed, Feb 18, 2009 at 2:51 PM, Cerebrus <[email protected]> wrote: > > > Arsalan is quite right... I checked your input strings and my results > > are as follows: > > > Line 1: split into 19 items > > Line 2: split into 20 items > > Line 3: split into 20 items > > Line 4: split into 20 items > > > Obviously, either the sample input you pasted here is incorrect or you > > have a lot many spaces in between each item that you are not > > accounting for. Either clean your input before processing or use a > > simple Regex like "([^\s]+)" to process it as is. > > > On Feb 18, 1:46 pm, sallushan <[email protected]> wrote: > > > Check the length of splitted array (MGCEP). It seems that there are > > > more than one spaces between the values. > > > > On Feb 17, 9:47 pm, Kenny <[email protected]> wrote: > > > > > Hello! > > > > > I'm trying out string.Split() for the first time and I'm very confused > > > > by my results. My input is a lot of lines like the following: > > > > > ILTOY46 310-410-21214-49860 WCHB1AX 0 0 0 1 > > > > IL05651 310-410-21209-5651 SCHB3AX 0 0 0 70 > > > > IL01737 310-410-21209-1737 SCHB3AX 0 0 0 38 > > > > IL05652 310-410-21209-5652 SCHB3AX 0 0 0 70 > > > > > I want to split on a whitespace between each (and then trim off the > > > > extra whitespaces, but I'll worry about the string.Trim() when I get > > > > to it). > > > > > My code looks like this: > > > > > string[] MGCEP = new string[7]; > > > > > MGCEP = searchLine.Split(); > > > > report.Text = MGCEP[0] + " " + MGCEP[1] + " " + MGCEP[2] + " " + MGCEP > > > > [3] + " " + MGCEP[4] + " " + MGCEP[5] + " " + MGCEP[6]; > > > > > My output in the text box looks like this: > > > > > ILTOY46 310-410-21214-49860 WCHB1AX 0 > > > > IL05651 310-410-21209-5651 SCHB3AX 0 > > > > IL01737 310-410-21209-1737 SCHB3AX 0 > > > > IL05652 310-410-21209-5652 SCHB3AX 0 > > > > > What's happening to my last 3 elements? Why am I getting > > > > ILTOY46 310-410-21214-49860 WCHB1AX 0 > > > > instead of > > > > ILTOY46 310-410-21214-49860 WCHB1AX 0 0 0 1? > > > > > Thank you for your help!- Hide quoted text - > > > > - Show quoted text -- Hide quoted text - > > - Show quoted text -
