String use function – acquisition

package cn.itcast_04;

/*

  • Row class collection function
  • int length (): Get the length of the character
  • Char charat (int negns): Gets the character at the specified index position
  • int indexof (int ch): Returns the index of the first place where the specified character appears in this string
  •          Примечание: почему это тип Int, а не тип Char
  •                   Ответ: потому что оба 97 и «А» представляют;
  •                           Когда он определяется как char ch; когда мы вступаем в 97, мы должны быть обязательными, чтобы получить «А»,
  •                           Однако при определении как int ch, это не требуется. Введите 97, 'A'                
  • Int Indexof (String Str): Returns the index of the first time this string is in this string
  • int indexof(int ch, int fromindex): Returns the index of the first time the specified character specifies the position of the string
  • Int Indexof(String Str, int fromindex): Returns the first index in the specified string after the specified position of that string
  • Low chain (run): from the specified location to the end
  • Substring STRING (int beginning, int end): From the specified location to the end of the specified location, cut the string
  •                                                   Примечание. Включая начальные символы, исключая конечный символ, то есть левый не включен вправо
  • */

public class StringDemo {

public static void main(String[] args) {
    // TODO Auto-generated method stub
         // Определить строковый объект
    String s = "HelloWorld";
    
         // int length (): получить длину персонажа
    System.out.println("s.length:" + s.length());
    System.out.println("-------------------------------------------------");
    
         // charcharat (int index): получить символ с указанной позицией индекса
    System.out.println("s.charAt():"+ s.charAt(9));
    System.out.println("-------------------------------------------------");
    
         // int indexof (int ch): возвращает индекс первого места, где указанный символ появляется в этой строке
    System.out.println("s.indexOf():"+ s.indexOf('o'));//4
    System.out.println("s.indexOf():"+ s.indexOf('t'));//-1
    System.out.println("-------------------------------------------------");
    
         // int indexof (String Str): возвращает индекс первого появления в этой строке в этой строке
    System.out.println("s.indexOf():"+ s.indexOf("or"));//6
    System.out.println("s.indexOf():"+ s.indexOf("oW"));//4
    System.out.println("-------------------------------------------------");
    
         // int int indexof (int ch, int fromindex): возвращает индекс первого раза после указанного символа, указанного в этой строке
    System.out.println("s.indexOf():"+ s.indexOf('o',0));//4
    System.out.println("s.indexOf():"+ s.indexOf('o',3));//4
    System.out.println("s.indexOf():"+ s.indexOf('o',7));//-1
    System.out.println("-------------------------------------------------");
    
         // int indexof (String Str, int fromindex): возвращает индекс первого раза после того, как указанная строка определяет положение строки.
    System.out.println("s.indexOf():"+ s.indexOf("or",0));//6
    System.out.println("s.indexOf():"+ s.indexOf("loW",3));//3
    System.out.println("s.indexOf():"+ s.indexOf("oW",7));//-1
    System.out.println("-------------------------------------------------");
    
         // String substring (int start): Проверьте строку из указанного местоположения, по умолчанию до конца
         System.out.println ("Строка перехвата подстроения:" + s.substring (3));
         System.out.println ("Substring Intercept String:" + s.substring (0));
    System.out.println("-------------------------------------------------");
    
         // String Substring (int start, int end): из указанного местоположения до конца указанного места, отрежьте строку
         System.out.println ("Substring Intercept String:" + s.substring (3,6)); // низкий
         System.out.println ("Substring Intercept String:" + s.substring (0, s.length ())); // helloworld
    System.out.println("-------------------------------------------------");

}

}

Reprinted from: https://www.cnblogs.com/zhangyuestuning/p/10837120.html

Leave a Comment