In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "what are the most commonly used methods of Java strings and arrays". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. String interception 1. The slice method returns a fragment of the string.
StrObj.slice (start [, end])
Description:
The strObj specified part of the start subscript starting at 0 is actually indexed. If start is negative, treat it as length+start, where length is the length of the string.
The strObj specified part of the end subscript that starts at 0 ends the index. If end is negative, treat it as length+end, where length is the length of the string.
For example:
012345
Var str = "ABCDEF"
Str.slice (2pr 4)
Results: CD
2. The substring method returns the substring at the specified location in the String object.
StrObj.substring (start,end)
Description:
Start indicates the starting position of the substring, with the index starting at 0.
End indicates the end of the substring, with the index starting at 0.
The substring method uses the smaller of both start and end as the starting point for the substring. If start or end is NaN or negative, replace it with 0.
For example:
012345
Var str = "ABCDEF"
Str.substring (2pr 4); / / or str.substring (4pr 2)
Results: CD
3. The substr method returns a substring of the specified length starting at the specified location.
StrObj.substr (start [, length])
Description:
The starting position of the substring required by start. The index of the first character in the string is 0.
The number of characters that length should include in the returned substring.
For example:
012345
Var str = "ABCDEF"
Str.substr (2pr 4)
Results: CDEF
4. Split is split into substrings and the result is returned as an array of strings.
StrObj.split ([separator [, limit]])
Description:
A separator string or regular expression object that identifies whether one or more characters are used when delimiting strings. If you omit this option, a single element array containing the entire string is returned.
Limit this value is used to limit the number of elements in the returned array.
For example:
Var str = "AA BB CC DD EE FF"
Alert (str.split (", 3))
Results:
AA,BB,CC
2. Array intercept 1, slice
Slice specifies that the elements in an array create a new array, that is, the original array will not change.
The slice of the array requires two parameters, the start point and the end point. It returns a new array of all elements from the beginning to the end.
'abc'.slice (1, 2) / / "b"
[14, 3, 77] .slice (1, 2) / / [3]
2 、 splice
Splice is the most powerful method of array in JS. It can delete, insert and replace array elements, and return the value to be operated. Shanghai Shangxue School web front-end training technical articles, pay more attention.
Splice deletion: arr.splice (1, 2) (delete items 1 and 2 in arr)
Splice insertion: arr.splice (1pink`) (insert two values before an element with an arr key of 1)
Splice substitution: arr.splice (1 and 2) (replace 1 and 2 elements in arr)
In addition, splice changes the original array. Don't be too surprised, this is exactly what splice intended.
Var x = [14,3,77]
Var y = x.splice (1,2)
Console.log (x) / / [14]
Console.log (y) / / [3,77]
3. Sort digit sort
/ / specify sorting function
Function sortNumber (a _ r _ b) {
Return a-b
}
Var arr = new Array (10,5,40,25, 1000, 1)
[xss_clean] (arr + "")
[xss_clean] (arr.sort (sortNumber))
This is the end of "what are the most commonly used methods for Java strings and arrays". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.