Click here to Skip to main content
15,885,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello ,

I am develpoing one project , in that im assigning the New alpha numeric code to the selected strings.

i.e strings are A000 to A010

C#
string s1 = A000 and String s2= A010;
 here String s3 is new string is retrived between s1 ande s2
here i need to do 

 if (s1 <= s3 && s3>=s2);
{ 
here i want to insert Alphanumeric code from s1 to s2;
}


is it applicable or any new suggestions.


Thanking you
Posted
Updated 14-Jan-15 1:10am
v2
Comments
Ankur\m/ 14-Jan-15 7:24am    
Do you mean you just need to extract the numeric part and compare them?

You probably meant following!

C#
List<string> list = new List<string>();
for (int index=0; index<=10; index++)
{
  List.Add(string.format("A{0:D3}", index);
}
</string></string>
 
Share this answer
 
if your requirement is adding items in correct order by using alphanumeric values, check below sample code
C#
void Main()
{
	SortedList<string,student> list = new SortedList<string,student>(new MyComparer());
	list.Add("A000",new Student(){Name ="A"});
	list.Add("A010",new Student(){Name ="F"});
	list.Add("A005",new Student(){Name ="G"});
	//list.Dump();
}
class MyComparer : IComparer<string>
{
   public int Compare(string a, string b)
   {
       var x = int.Parse(Regex.Replace(a, "[^0-9]", ""));
        var y = int.Parse(Regex.Replace(b, "[^0-9]", ""));
        if (x != y) return x - y;
        return -1 * string.Compare(a, b);
   }
}

class Student 
{
  public string Name{get;set;}
}

</string>

you can use SortedList and it will sort item based on given comparer, here i have added custom comparer for your alphanumeric values.
 
Share this answer
 
.NET String object has a built in comparison method...Use it!
http://msdn.microsoft.com/en-us/library/System.String.Compare(v=vs.110).aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900