Try using Regular Expressions:
string str = "ITV2_123";
if( Regex.IsMatch( str, @"(P|I|C)TV\d+_\d+" ) )
{
Console.WriteLine( "String OK" );
}
The expression can be adjusted for your specific rules.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This is a trivial problem but I cannot get a solution.
I am trying to make my code recognize strings like the following:
"PTV1_3000", "ITV3_4000"
The sub-string should contain a root-like "PTV", "ITV", "CTV" followed by one or more integer numbers followed by "_".
I tried different flavors of the following expression:
string str = "ITV2_123";
if(str.Contains("ITV[0-9]*$_"))
{
Console.WriteLine("String OK)");
}
else
{
Console.WriteLine("string KO");
}
Console.ReadKey();
Is it possible to find alphanumeric sub-strings in a string?
Thank you so much.
Try using Regular Expressions:
string str = "ITV2_123";
if( Regex.IsMatch( str, @"(P|I|C)TV\d+_\d+" ) )
{
Console.WriteLine( "String OK" );
}
The expression can be adjusted for your specific rules.