Home > Java > javaTutorial > What is the use of regionMatches method in java

What is the use of regionMatches method in java

PHPz
Release: 2023-05-04 22:19:05
forward
1111 people have browsed it

regionMatches method:

Note: The regionMatches() method is used to detect whether two strings are equal within a region.

public class RegionMatches{
	public static void main(String[] args) {
		int number = 0;
		String s = "student;entropy;ENgage,English,client,eye";
		String q="en"; //需要查找的字符串
		for (int k=0;k<s.length();k++){
		//true为不区分大小写,k为所有字符串,q为需要查找的字符串,0为从字符串1的位置开始,2为需要查找的字符串长度为2
		if(s.regionMatches(true, k, q, 0, 2)){ 
				number++;
				System.out.println("en字符在字符串的第"+k+"个位置");
			}
		}
		System.out.println("含有‘en&#39;子串的字符串的总数有:"+number);
	}
}
Copy after login

Running result:

en character is in the 4th position of the string
en character is in the 8th position of the string
en character is in the string The 16th position
en character is at the 23rd position of the string
en character is at the 34th position of the string
The total number of strings containing the 'en' substring is: 5

The above is the detailed content of What is the use of regionMatches method in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template