substring ()
It has two forms, the first of which is:String substring (int startIndex)
The second type is:String substring (int startindex,int endIndex)
Y concat ()
Connect two strings
replace ()
Replace it in two forms, the first form with a character in the invocation string where all occurrences of a character are replaced, in the form of the following:
String replace (char Original,char replacement)
Example:String s= "Hello". Replace ('l ', 'w ');
The second form is to replace another sequence of characters with one character sequence, in the following form:
String replace (charsequence original,charsequence replacement)
trim ()
Remove the start and end spaces
Y valueOf ()
Convert to String
Y tolowercase ()
Convert to lowercase
Y touppercase ()
Convert to uppercase
Y Length ()
Gets the length of the string
Example:char chars[]={'a ', 'B '. ' c '};
String S=new string (chars);
int Len=s.length ();
Y charAt ()
Intercept a character
Example:char ch;
Ch= "abc". CharAt (1);
The return value is 'B '
Y getChars ()
Intercept multiple characters
void GetChars (int sourcestart,int sourceend,char target[],int targetstart)
SOURCESTART Specifies the subscript for the start character of a substring
SOURCEEND Specifies the subscript for the next character after the substring ends. Therefore, the substring contains characters from Sourcestart to sourceEnd-1.
Target specifies an array of received characters
Targetstart Target starts copying sub-string subscript values
Cases:
String s= "This isa demo of the GetChars method." ;
Char Buf[]=new char[20];
S.getchars (10,14,buf,0);
Y getBytes ()
one way to replace GetChars () is to store characters in a byte array, which is getBytes ()
Example:String s = "hello! Hello!" ";
byte[] bytes = S.getbytes ();
Y ToCharArray ()
Example:String s = "hello! Hello!" ";
char[] ss = S.tochararray ();
equals () and equalsignorecase ()
Comparison of two strings
Y regionmatches ()
Used to compare a particular area of a string with another specific area, which has an overloaded form that allows the case to be ignored in comparisons.
Boolean regionmatches (int startindex,string str2,int
Str2startindex,int numChars)
Boolean regionmatches (Boolean ignorecase,int startindex,string
Str2,int str2startindex,int NumChars)
Y startsWith () and endsWith ()
The StartsWith () method determines whether to start with a specific string, and theEndwith () method determines whether to end with a specific string
equals () and = =
The Equals () method compares the characters in a string object, and the= = operator Compares whether two objects refer to the same instance.
Example:String s1= "Hello";
String S2=new string (S1);
S1.eauals (S2); True
S1==s2;//false
Y compareTo () and comparetoignorecase ()
Comparing strings
Y indexOf () and lastIndexOf ()
IndexOf () finds the first occurrence of a character or substring.
LastIndexOf () finds the character or substring that is the last occurrence.
Y StringBuffer
constructor function
StringBuffer defines three constructors:
StringBuffer ()
StringBuffer (int size)
StringBuffer (String str)
StringBuffer (charsequence chars)
The following are StringBuffer related functions:
ü Length () and capacity ()
The current length of a stringbuffer can be obtained through the length () method , while the entire assignable space is obtained through the capacity () method.
ü ensurecapacity () sets the size of the buffer
void ensurecapacity (int capacity)
ü setLength () sets the length of the buffer
void setLength (int len)
ü charAt () and Setcharat ()
Char charAt (int where)
void Setcharat (int where,char ch)
ü GetChars ()
void GetChars (int sourcestart,int sourceend,char target[],int targetstart)
ü Append () can connect string representations of any type of data to the end of the called StringBuffer object.
Example:int a=42;
StringBuffer sb=new StringBuffer (40);
String s=sb.append ("a="). Append (a). Append ("!" ). toString ();
ü Insert () inserts a string
StringBuffer Insert (int index,string str)
StringBuffer insert (int index,char ch)
StringBuffer Insert (int index,object obj)
index specifies the subscript for inserting a string into the position of the StringBuffer object.
ü reverse () reverses the characters in the StringBuffer object
StringBuffer reverse ()
ü Delete () and Deletecharat () remove characters
StringBuffer Delete (int startindex,int endIndex)
StringBuffer deletecharat (int loc)
ü replace () replacement
StringBuffer replace (int startindex,int endindex,string str)
ü substring () intercept sub-string
String substring (int startIndex)
String substring (int startindex,int endIndex)
Java String processing functions