1. chatat () -- extract the specified string
2. codepointat () -- extract index character code points
Java code
- /**
- * Author: Sunshine flavor
- * Function: charat () and codepointat () common methods of the string class ()
- * Date: 2010/11/07
- **/
- Public ClassStringdemo {
- Public Static VoidMain (string [] ARGs ){
- String str1 = "abcdefg ";
- CharCharacter = str1.charat (0 );
- System. Out. println ("using charat () method" +
- "Extract characters from a string. The result is:" + signature );
- IntCodepoint = 0;
- For(IntI = 0; I <8; I ++ ){
- Try{
- Codepoint = str1.codepointat (I );
- }Catch(Stringindexoutofboundsexception E1 ){
- System. Out. println ("index value called by codepointay ()" + I +
- "The length of the string to be queried is exceeded! ");
- }Finally{
- Try{
- System. Out. println (str1.charat (I)
- + "Unicode code" + ":" + codepoint );
- }Catch(Stringindexoutofboundsexception E2 ){
- System. Out. println ("charat () called index value" + I +
- "The length of the string to be queried is exceeded! ");
- }
- }
- }
- }
- }
- /* Out:
- Use the charat () method to extract characters from a string. The result is:.
- Unicode code of a: 97
- Unicode code of B: 98
- C Unicode code: 99
- D Unicode code: 100
- The Unicode code of E is: 101
- Unicode Code of F: 102
- Unicode code of G: 103
- The index value 7 called by codepointay () has exceeded the length of the string to be queried!
- The index value 7 called by charat () has exceeded the length of the string to be queried! */
{
Function onclick ()
{
DP. Sh. toolbar. copytoclipboard (this); Return false;
}
} "Href =" # ">