string s = "0082002100071254 INR 008200    XYZAPQRDEFGHIJK            0.00 Cr    03100";
string[] arraytempline2 = s.split(','); 
MessageBox.Show("Length of Line : " + arraytempline2.Length);

After spliting its giving the length as 1
But i want to seperate the above string
And According to me its length should be 6
But i am not getting what is wrong with my code

Recommended Answers

All 4 Replies

you are setting the split symbol as ','. since you have no commas in your string, that's why it's not splitting anything.

you have to set the split symbol as a ' ', (space)

The Split method cannot find a ',' (comma) character to split your string, so it returns the whole string. That is why the arraytempline2 string array returns 1 as Length. arraytempline2[0] = s
I think it's better to use the LastIndexOf method, looking for a space and then chop your string with the SubString method.

If you split on space you'll get 24 parts. I'll leave you with this link to understand why

Thank Momerath for giving valuable time
I got what you are saying is Right
Substring is one of the solution to get three string from one string

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.