Check if a string exists between two letters

I am working on deciphering VIN numbers in useful information, and for the country they give a series of double letters (EG: SA-SM - United Kingdom). How to verify that SG is between SA and SM? I was thinking about hex, but it cannot be converted to hex because it passes by E.

+1
source share
4 answers
if (String.Compare("SG","SA") > 0 && String.Compare("SG","SM") < 0)
{  // SG between SA and SM
}

Ignore case

if (String.Compare("SG","SA",true) > 0 && String.Compare("SG","SM",true) < 0)
{  // SG between SA and SM
}

You can also use one of CurrentCulture, CurrentCultureIgnoreCase, InvariantCulture, InvariantCultureIgnoreCase, Ordinal, OrdinalIgnoreCase ( msdn docs )

if (String.Compare("SG","SA",CurrentCultureIgnoreCase) > 0 && String.Compare("SG","SM",CurrentCultureIgnoreCase) < 0)
{  // SG between SA and SM
}
+6
source
value[0] == 'S' && value[1] >= 'A' && value[1] <= 'M'
+3
source

, hex - : base-26?

var str = "SK";
var base26 = 26*(str[0]-'A')+(str[1]-'A');

, .

+2
source

Try it like this:

string test= "SASGSM";
if(test.IndexOf("SG") > -1) {

 //your action

} 
0
source

Source: https://habr.com/ru/post/1612351/


All Articles