split and sort numbers and aplhabets

mathanraj76

Member
Joined
Feb 4, 2013
Messages
6
Programming Experience
Beginner
Hi..

How i want to split and sort number and alphabets in vb.net and save into excel file in vb.net

for an example i have data in excel file :

1A
2 A
3 C
88 C
30 E
100 F
100 B
100 A
45 G

AND I want it the output in excel file by split number and alphabets

1 A
2 A
3 C
30 E
45 G
100 A
100 B
100 F


I have attache sample files

Thanks
Mraj
 

Attachments

  • Data.txt
    236 KB · Views: 23
First of all, that is really two completely separate questions. How to sort that data and how to write it to Excel are completely unrelated. I'm going to address the first part but I'm asking you to post a new thread dedicated specifically to writing the data to Excel.

I'm going to provide step-by-step instructions and I would like to see you try to follow those instructions. By all means post back if you have issues but each step is quite simple on its own so there's really no reason that you can't do it. If you don't know exactly what to do then research it for yourself first.

1. Call File.ReadAllLines to read the file into an String array.
2. Create two new arrays with the same size as the first, one type Integer and the other type String.
3. Use a For loop to loop through the first array.
4. Use the loop counter as an index to get an element from the first array.
5. Call Split on that element to split the number and the letter.
6. Convert the number to an Integer and then put those two values into the second and third arrays, using the loop counter as an index.
7. When the loop has completed, call Array.Sort. There is an overload that takes two arrays, one containing keys and one containing values. In your case, the Integer array is the keys.

You now have two sorted arrays and you can loop through them and write your data to Excel.
 
Back
Top