. NET automatically intercepts the letter before the string.

Source: Internet
Author: User

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;
}
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.