String extraction algorithm in the text box

Source: Internet
Author: User

Today, I want to develop a batch Comparison Program for extracting ID cards. I wrote a basic algorithm, but I have not yet verified how to extract ID card numbers (the last character of ID card can be a character)

Extract numeric strings only

The algorithm for serial number extraction in the text box:
1. determine the sequence stream of the text box, such as label_stram.text.
2. Determine a list box to separate the extracted numeric strings, such as ListBox
3. Identify and obtain numeric strings by counter and add them to the ListBox element one by one
/// <Summary>
/// Extract a numeric string from the string
/// </Summary>
/// <Param name = "str"> </param>
/// <Returns> </returns>
Public void storenumstr (string Str)
{
// Start indexing with numeric characters
Int I _start =-1;
// Numeric character final index
Int I _end =-1;
// Counter
Int COUNT = 0;

While (count <= Str. length)
{
If (I _start =-1)
{
// When the start index does not exist, the number is immediately recorded to start the index.
If (char. isnumber (STR, count) = true)
{
I _start = count;
// Count increases after detection
Count = count + 1;
}
Else
{
// Count and Add 1 If no result is found
Count = count + 1;
}
}
Else
{
// When the index starts to exist, it determines that the character currently being read is a number.
If (char. isnumber (STR, count) = true)
{
I _end = count;
Count = count + 1; // enter the next Analysis
}
Else
{
// When the index starts to exist, it determines that the character currently being read is not a number;
I _end = count-1;
// Truncate a numeric string
ListBox. item. Add (Str. substring (I _start, I _end-i_start + 1 );
// Clear the start index;
I _start =-1;
I _end = 1;
// Count continues to increase
Count = count + 1;
}
}
} // End while)
} // This method ends

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.