About converting capital Chinese amount-Newly learned Java function collation

Source: Internet
Author: User

ToCharArray
   ToCharArray ()
converts this string to a new character array.
Return:
a newly assigned character array whose length is the length of this string, and the content is initialized to a sequence of characters containing this string representation
Insert () function
Buffer.insert (0,100); 100
Buffer.insert (0,2.5f); 2.5100
Buffer.insert (3, ' * '); 2.5*100
Buffer.insert (0,250.0d); 250.02.5*100
Buffer.insert (5, "is equal to"); 250.0 is equal to 2.5*100
append () function
Append (String str), connecting a string to the end. Append has many overloaded methods.
Delete (int start,
int end) Deletes the string at the specified position.
Deletecharat (int index) deletes the character of the specified corner mark.
There are many ways to say and not to finish. Look at the API documentation. It's very simple.

It is also important to note that StringBuffer is thread-safe and is used mostly for multithreading.
Sometimes it is necessary to build shorter strings into long strings, such as keystrokes or words from a file. The use of string joins is inefficient. Each time a connection string is built, a new string object is constructed, which is a time-consuming and wasteful space. You can use StringBuffer.
definition of parseint ():The parseint () function parses a string and returns an integer. [1] syntax for parseint (): parseint (string s, [int radix]) [1] where the parameter string s, required, represents the string to be parsed. [1] int radix, optionally, represents the cardinality of the number to parse. [1] The function uses the cardinality specified by the second parameter, with a value between 2 and 36. If this argument is omitted or its value is 0, the number is parsed based on 10. If it starts with "0x" or "0X", it will have a base of 16. [1] If the parameter is less than 2 or greater than 36, then parseint () will return NaN. [1] In addition to the first character can be used to represent a negative value of the ASCII minus '-' (' \u002d '), the character in the string must be a decimal number. Returns the resulting integer value as if it were given a parseint (java.lang.String, int) method as an argument to cardinality 10. In short, parseint () in JavaScript is the conversion of a string variable into an integer int. Split Method
Splits a string into substrings and returns the result as an array of strings.
Stringobj.split ([Separator,[limit]])
Stringobj
Required option. The String object or text to be decomposed. The object is not modified by the split method.

Separator
Options are available. A string or regular expression object that identifies whether one or more characters are used when separating the string. If you suddenly
This option returns a single-element array that contains the entire string.

Limit
Options are available. This value is used to limit the number of elements in the returned array.

Description
The result of the split method is an array of strings, which are decomposed in every position where separator occurs in stingobj.
。 Separator is not returned as part of any array element. Example:
public class Splitdemo {

public static string[] ss = new STRING[20];

Public Splitdemo () {

String s = "The rain in Spain falls mainly in the plain.";
Decompose at each space character.
SS = S.split ("");
}

public static void Main (string[] args) {

Splitdemo demo = new Splitdemo ();
for (int i = 0; i < ss.length; i++)
System.out.println (Ss[i]);
}

}

Program results:
The
Rain
Inch
Spain
Falls
Mainly
Inch
The
Plain.

Public string[] Split (string regex)
The name of the parameter here is the Regex, which is the regular expression (regex). This parameter is not a simple segmentation of the character, but a regular expression, look at the split method implementation code to strengthen our confidence:

Public string[] Split (string regex, int limit) {
return Pattern.compile (Regex). Split (this, limit);
}
Split's implementation directly calls the split method of the Matcher class. The reader already knows, ". "There are special meanings in regular expressions, so we must escape when we use them."
As long as the
string[] names = Value.split (".");
Switch
string[] names = Value.split ("//.");
You can do it.

Output Result:
192
168
128
33

Additional notes:
Public string[] Split (string regex,int limit) splits this string by matching a given regular expression.
The array returned by this method contains each substring of this string, terminated by another substring that matches the given expression, or terminated by the end of the string. The substrings in the array are arranged in the order in which they are in this string. If the expression does not match any part of the input, the resulting array has only one element, that is, the string.

The limit parameter controls the number of times the pattern is applied, thus affecting the length of the resulting array. If the limit n is greater than 0, the pattern will be applied up to n-1 times, the length of the array will not be greater than N, and the last item of the array will contain all inputs that exceed the last matching delimiter. If n is not positive, the pattern is applied as many times as possible, and the array can be any length. If n is zero, the pattern will be applied as many times as possible, the array can have any length, and the trailing empty string will be discarded.

For example, the string "Boo:and:foo" uses these parameters to produce the following results:

Regex Limit Results

: 2 {"Boo", "And:foo"}
: 5 {"Boo", "and", "foo"}
:-2 {"Boo", "and", "foo"}
o 5 {"B", "", ": And:f", "", ""}
o-2 {"B", "", ": And:f", "", ""}
o 0 {"B", "", ": And:f"}

This form of method call Str.split (regex, N) produces exactly the same result as the following expression:

Pattern.compile (Regex). Split (str, n)

Parameters:
Regex-bound Regular expression
Limit-result threshold, as described above
Return:
A string array that splits this string according to the match of the given regular expression, resulting in this array
Thrown:
Patternsyntaxexception-If the syntax of the regular expression is invalid
Start from the following versions:
1.4

Public string[] Split (string regex) splits this string based on the match of the given regular expression.
The method acts as if the two-argument split method is called with the given expression and the limit parameter. Therefore, the trailing empty string is not included in the result array.

For example, the string "Boo:and:foo" yields results with these expressions:

Regex Results
: {"Boo", "and", "foo"}
o {"B", "", ": And:f"}

Parameters:
Regex-bound Regular expression
Return:
An array of strings that is generated by splitting the string according to the match of the given regular expression.
Thrown:
Patternsyntaxexception-If the syntax of the regular expression is invalid

NumberFormat represents a formatted class of numbers, that is, a number can be displayed according to local style habits.

This class is defined as follows:

Public abstract class NumberFormat extends Format


Messageformat, DateFormat, NumberFormat is the format of the three commonly used subclasses, if you want to further complete a good internationalization program, you will definitely need to use such three classes at the same time, according to different countries show the form of credit.

This class is still in the java.text package, so you can import the package directly.

[Java]View Plaincopy
  1. Import java.text.*;
  2. Public class numberformatdemo01{
  3. public static void Main (String args[]) {
  4. NumberFormat NF = null; //Declare a NumberFormat object
  5. NF = numberformat.getinstance (); //Get the default number format display
  6. SYSTEM.OUT.PRINTLN ("formatted number:" + nf.format (10000000));
  7. SYSTEM.OUT.PRINTLN ("formatted number:" + nf.format (1000.345));
  8. }
  9. };
Basic use of DecimalFormat

is a subclass of the NumberFormat class, the main function is to format the number of use, of course, in the format of the number is more convenient than the direct use of NumberFormat, because you can directly specify the user-defined way to format the operation, Similar to the previous SimpleDateFormat, if you want to perform a custom format operation, you must specify a template for the formatting action.


[Java]View Plaincopy
  1. Import java.text.*;
  2. Class formatdemo{
  3. public void Format1 (String pattern,Double value) { //This method is specifically used to complete the formatted display of numbers
  4. DecimalFormat df = null; //Declare an object of the DecimalFormat class
  5. DF = New DecimalFormat (pattern); //Instantiating objects, passing in templates
  6. String str = df.format (value); //format numbers
  7. SYSTEM.OUT.PRINTLN ("use" + pattern
  8. + "formatted number" + Value + ":" + str);
  9. }
  10. };
  11. Public class numberformatdemo02{
  12. public static void Main (String args[]) {
  13. Formatdemo demo = new Formatdemo (); //class for formatting objects
  14. DEMO.FORMAT1 ("###,###.###",111222.34567);
  15. DEMO.FORMAT1 ("000,000.000",11222.34567);
  16. DEMO.FORMAT1 ("###,###.###¥",111222.34567);
  17. DEMO.FORMAT1 ("000,000.000¥",11222.34567);
  18. DEMO.FORMAT1 ("##.###%",0.345678);
  19. DEMO.FORMAT1 ("00.###%",0.0345678);
  20. DEMO.FORMAT1 ("###.###\u2030",0.345678);
  21. }
  22. };

About converting capital Chinese amount-Newly learned Java function collation

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.