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 -

Reply via email to