当前位置:网站首页>Use of split() method in string class
Use of split() method in string class
2022-06-13 00:15:00 【Tomatoes are sleepy】
String Class split Use of methods
see api Will find ,split Method has method overload
One is split(String regex) One is split(String regex,int limit)
First explain split(String regex,int limit)
First look at the official explanation :
Official explanation :
public String[] split(String regex,
int limit) Split this string into the given regular expression The matching of . The array returned by this method contains each substring of this string , The string is 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 their order in this string . If the expression does not match any part of the input , The generated array has only one element , That is, this string .When there is a positive width match at the beginning of this string , Contains an empty leading substring at the beginning of the result array . Zero width matching at the beginning will not produce such an empty leading substring .
limit The parameter controls the number of times the mode is applied , Therefore, the length of the generated array is affected . If the limit n Greater than 0, The mode can be applied at most n -1 Time , The length of the array is not greater than n
, The last entry of the array will contain all inputs beyond the last matching delimiter . If n Right and wrong , Then the pattern will be applied as many times as possible , And the array can have any length .
If n by 0, The pattern will be applied as many times as possible , Arrays can have any length , And the trailing empty string will be discarded .
understand : Is to satisfy the string regex The part of the string is replaced by an empty string and split from here , And convert it into an array
String Regex Is a regular expression ,limit Is the number of cuts
Now? limit There are three situations :1. Positive numbers 2. negative 3. be equal to 0
Positive numbers :
split Method will cut the string (limit-1) Time , That is to say, if limit =
1, that split The array length is 1, Is the original string , It just becomes an array . And that is regex Does not satisfy any characters in the string , It will also convert the original string into an array , If it is 2 Words , Then it will cut 1 Time , If it is 3 Words , cutting 2 Time




negative :
split Will cut an infinite number of times , That is, all the strings that satisfy regex Replace all with empty strings , Converted to an array
Whether it's -1 still -10, The result is the same


0:
split It also cuts an infinite number of times , Also, all the strings that satisfy regex Replace all with empty strings , But the empty string at the end of the string will be cleared and converted into an array


Look again. split(String regex), Is a default limit yes 0 Of split(String regex,int limit)
Yes split() The understanding of the method is a step deeper ,nice
边栏推荐
- Buuctf-[ciscn 2019 preliminary]love math
- 【Matlab】符号计算
- [LeetCode]28. Implement strstr()
- On the parameters of main function in C language
- The difference between caching and buffering
- The whole process from entering URL to displaying page (interview)
- Actual combat | UI automation test framework design and pageobject transformation
- Interprocess communication - shared memory shmat
- 【Matlab】矩阵操作
- [matlab] 3D curve and 3D surface
猜你喜欢

Do you really use the buffer buffer in PostGIS?
![[C] Inverts the binary of a decimal number and outputs it](/img/40/dcbe0aac2d0599189697db1f0080b5.jpg)
[C] Inverts the binary of a decimal number and outputs it

USTC of China University of science and technology: Minrui Wang | distribution network voltage stabilization based on transformer Multi-Agent Reinforcement Learning

Explain bio, NiO, AIO in detail
![[hcie discussion] multicast igmp-a](/img/1a/74c6e698c9a6a6c7a4c32153a0a277.png)
[hcie discussion] multicast igmp-a
![[matlab] symbol calculation](/img/a5/7682a465ca2813a83114c091580c53.png)
[matlab] symbol calculation

Masa auth - overall design from the user's perspective

Divicon est toujours utilisé dans le leaflet de l'ère H5?

Video tracker error troubleshooting

Pytorch loading model error resolution
随机推荐
Do you really use the buffer buffer in PostGIS?
睡前小故事之MySQL起源
Divicon est toujours utilisé dans le leaflet de l'ère H5?
【Matlab】基础知识
Interprocess communication - shared memory shmat
How to quickly query the online status of mobile phones
[LeetCode]3. The longest substring without duplicate characters forty
Matlab【路径规划】—— 无人机药品配送路线最优化
2022 constructor - Equipment direction - General Foundation (constructor) operation certificate examination questions and simulation examination
Start of u-boot_ Armboot analysis (I)
[LeetCode]21. Merge two ordered linked lists twenty-nine
La différence entre philosophie et littérature
在 Golang 中构建 CRUD 应用程序
leaflet中如何优雅的解决百度、高德地图的偏移问题
PMP renewal | PDU specific operation diagram
Start of u-boot S analysis (IV)
The e-commerce employee changed the product price to 10% off after leaving the company, and has been detained
Is divicon still used in leaflet in H5 era?
Pytorch loading model error resolution
String类中split()方法的使用