To read 20 characters of a string, you can use the substring method. So
myString = myString.Substring(0,20);
will return the first 20 characters. However, this will throw an exception if you have less than 20 characters. You can make a method like this to give you the first 20 or the whole line if it is shorter.
string FirstTwenty( string input ){ return input.Length > 20 ? input.Substring(0,20) : input; }
Then to compare them
if(FirstTwenty(myString1).CompareTo(FirstTwenty(myString2)) == 0){
In case of UpperCase use this function
if (FirstTwenty(mystring1).Equals(FirstTwenty(myString2), StringComparison.InvariantCultureIgnoreCase)) {
Øyvind Bråthen
source share