Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, April 26, 2012 5:57 AM
Good day to all,
I develop a code to get numbers as input from word file and compare it with the contents. It works properly
Here is the code with conditions
string strFilterWord = string.Empty;
strFilterWord = strWord.Replace
("(",string.Empty).Replace(')', ' ').Replace('.', ' ').Replace(';', ' ').Replace(':', ' ').Trim();
if (strFilterWord.Length == 4)
if (Convert.ToInt32(strFilterWord) > 1700 && Convert.ToInt32(strFilterWord) < 2100)
if (strSplitValue[0].Contains(strFilterWord))
Note:
- For the above code i use the condition: Input value is occur in four digits only and it is between 1900 to 2012. (Ex:Year)
- In a paragraph the year information is occur only once.
- Since i remove all the special characters and fetch only the numbers.
- strFilterWord is the year information and strSplitValue[0] is the string which contains the all datum.
Similarly i need to compare the alphanumeric value [Ex: 2012a]. I have an idea to use regex condition, but i need to know is there any other way to compare
How is it possible to compare?
Regards
All replies (5)
Friday, April 27, 2012 6:47 AM âś…Answered
Hello Harvest,
Alphanumeric is a term from the past (cobol time). That data is called currently strings (in fact strings of characters).
For complex validation or whatever of that are used the Regular expressions which are implemented in .Net and therefore in C#.
As soon as you see that you need more than 5 lines of code to evalutate a string, use the regular expression, then it becomes more reliable and processes faster.
Regular expressions.
http://msdn.microsoft.com/en-us/library/30wbz966(v=vs.100).aspx
Success
Cor
Friday, April 27, 2012 6:36 AM
I believe to compare alpha numeric values, with actual numeric comparison, you need to get the 2012a converted to 2012.
One approach is to use a custom IComparer and inside the Compare() method do the numeric parsing.
public partial class Form1 : Form, IComparer
public int Compare(object x, object y)
{
int i = int.Parse(GetNumericOf(x));
int j = int.Parse(GetNumericOf(y));
return i.CompareTo(j);
}
If you do have regex solution in hand, it would the best solution.
Resolving n Evolving in C# (http://jeanpaulva.com)
Friday, April 27, 2012 6:54 AM
If there is some value like your example "2112a", this value cannot be converted to a number (to string), and thats why you cannot compare it (biger, higher, longer, or what ever). You can only do that with numbers only.
But if you still wanna do it, simple "remove" last character, and you will have a number which you then can compare.
Mitja
Friday, April 27, 2012 8:36 AM
Hi Cor Ligthert,
Basically i am from MF Domain and now it is time to change into MS, Thats way i mentioned Alphanumeric.
Thanks for your Reply.
Deepak G.
Friday, April 27, 2012 8:37 AM
@Mitja,
But my process need to compare the data with alphabetic values.
Regards,
Deepak G.