Traditional Chinese numbers, regular expressions... No, traditional Chinese Regular Expressions

Source: Internet
Author: User

Traditional Chinese numbers, regular expressions... No, traditional Chinese Regular Expressions

1 package test; 2/* 3 * 10th question: amount conversion, Arabic numerals into the traditional Chinese form. For example, 101000001010 is converted to, x 0x0x0x4. Step 1. create a conversion method converNumber (long number) 2. convert Arabic form into traditional Chinese Form 3. 0 operation 4. regular Expression Replacement Operation 5 **/6 public class Test17 7 {8 public static void main (String [] args) 9 {10 // TEST 11 System. out. println (convertNumber (3500908); 12 System. out. println (convertNumber (101000001010L); 13 System. out. println (convertNumber (0000000000l); 14} 15 public static String convertNumber (long nu Mber) 16 {17 // define character array storage Chinese digital writing format 18 final char [] chineseNumber = new char [] {'0', 'yi', 'er ', 'san', 'Ta', 'wu', 'loan', 'taobao '}; 19 // define a character array to store Chinese numbers in 20 final char [] units = new char [] {'circle ', 'scush', 'done', 'done ', 'wan', 'pick', 'taobao', 'taobao', 'yiyi', 'taobao', 'taobao '}; 21 // define a string buffer to store characters 22 StringBuilder sb = new StringBuilder (); 23 int index = 0; 24 long lastNumber = 0; 25 while (number! = 0) 26 {27 lastNumber = number % 10; 28 sb. insert (0, units [index ++]); 29 sb. insert (0, chineseNumber [(int) lastNumber]); 30 number = number/10; 31} 32 // use the regular expression 33 return sb. toString (). replaceAll ("Zero [zhibai]", "zero "). replaceAll ("0 + 1 million", "1 million "). replaceAll ("0 {4} million", "0 "). replaceAll ("Zero + ten thousand", "Ten Thousand "). replaceAll ("Zero + circle", "circle "). replaceAll ("Zero +", "zero") + "whole"; 34} 35}

 


Regular Expression, I thought about the condition for two days: only numbers, letters, underscores, length 1-30, and not all numbers

^ (?! \ D + $) \ w {1, 30} $
Small case

Only regular expressions of numbers can be entered.

You do not need to write regular expressions. You can do this:

Try {
Convert. ToInt32 (TextBox7.Text );
} Catch {
Label3.Text = "enter a number ";
}

-------------

No. Write it like this:

Regex rg = new Regex (@ "^ \ d * $ ");
If (rg. IsMatch (this. TextBox1.Text, 0 ))
{
This. TextBox1.Text = "OK ";
}
Else {
This. TextBox1.Text = "no ";
}

------------------

If try {} catch and catch are used, you only need to make corresponding prompts in catch. if an exception is caught, the program will automatically stop running.
For example:
Try {
Convert. ToInt32 ("aaa ");
} Catch {
Label. Text = "incorrect input"; // if an exception is caught, the program will go to this sentence and will not be executed.
}
Int ii = 0; // if no exception is caught. That is, if the input is correct, it will be executed from here.

If regular expressions are used, enter the correct logic in the "OK" that I wrote, and prompt that the input is incorrect in the "no.

In fact, you just want to verify whether the input is a number. it does not need to be so troublesome. drag a verification control CompareValidator. set the ControlToValidate attribute to the control to be verified. set the Operator attribute to DataTypeCheck. set Type to Integer. in addition, the advantage of this is that you do not need to send back the page.

For your 0 points... typing is exhausted ..

--------------------

CompareValidator is not only used to compare the values of the two. It also has many functions. For details, see F1.DataTypeCheck to check the data type.

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.