To develop your own project, you need to write a function to obtain the prefix of the component number, because the component number prefix is composed of the component type and then random numbers, however, the material type may start with one, two, or three other letters, and I cannot judge each type, so it is difficult to encode the character to process the code. In fact, if you think about it carefully, you will have the following CODE. Record the CODE yourself.
Using System;
Using System. Collections. Generic;
Using System. Text;
Using Microsoft. VisualBasic;
Using System. Text. RegularExpressions;
Namespace ConsoleAppTest
{
Public class StringHandle
{
/// <Summary>
/// Returns a string prefixed with letters.
/// </Summary>
/// <Param name = "sourceString"> string to be checked </param>
/// <Returns> </returns>
Public static string getPreCharecterString (string sourceString)
{
Char [] initialChar = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'h ', 'I', 'J', 'k', 'l', 'M', 'n', 'O', 'P', 'Q', 'R ', 'S ', 't', 'U', 'V', 'w', 'x', 'y', 'z ',
'A', 'B', 'C', 'D', 'E', 'E', 'F', 'G', 'h', 'I', 'G ', 'k', 'l', 'M', 'n', 'O', 'P', 'Q', 'R', 's','t ', 'U', 'V', 'w', 'x', 'y', 'z'}; // 52 letters
// String initialString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
// Char [] initialDigit = {'0', '1', '2', '3', '4', '5', '6', '7 ', '8', '9 '};
// InitialChar = initialString. ToCharArray ();
If (string. IsNullOrEmpty (sourceString ))
{
Return string. Empty;
}
Else
{
String tempStr = string. Empty; // used for temporary storage
Char [] sourceChar = sourceString. ToCharArray (); // convert the original character to an array of positive characters
Int length = sourceString. Length; // obtain the string length.
For (int I = 0; I <length ;)
{
// If (Regex. IsMatch (sourceChar [I]. ToString (), @ "^ [+-]? \ D * [.]? \ D * $ ") // specifies whether the matching is a number. If yes, the system directly redirects to the OK tag.
//{
// Goto OK;
//}
If (! Regex. IsMatch (sourceChar [I]. ToString (), @ "^ [A-Za-z]") // match non-letters
{
Goto OK;
}
Char currentChar = sourceChar [I];
Foreach (char okChar in initialChar)
{
If (okChar = currentChar)
{
TempStr + = okChar;
}
}
I ++;
}
OK:
Return tempStr;
}
}
}