Substring
Public String substring (int beginIndex) returns a new String, which is a substring of this String. The substring starts with a character at the specified index until the end of the string.
For example:
"Unhappy". substring (2) returns "happy"
"Harbison". substring (3) returns "bison"
"Emptiness". substring (9) returns "" (an empty string)
Parameters:
BeginIndex-the index at the beginning (including ).
Return value:
The specified substring.
Throw:
IndexOutOfBoundsException-if beginIndex is negative or greater than the length of this String object
Example
/*
* If the content is too long, the xml file may be too large and loading is too slow.
* From the seo perspective, all outputs are good for search engines, but the content is usually not too much.
* To prevent the css from being subject to space wrapping, the space is replaced by a regular expression. Therefore, the first 100 characters are truncated and the content displayed on the page is subject to css control.
* Zdz works
| The code is as follows: |
Copy code |
|
*/
// Str. trim (). replaceAll ("\ s + ","");
String contenttemp = rs. getString (contentName). trim (). replaceAll ("\ s + ","");
// NpfDebug. print (contenttemp. length ());
If (contenttemp. length ()> 100) {// Intercept if the length is greater than 100
Contenttemp = contenttemp. substring (0,100 );
// NpfDebug. print ("contenttemp. length ()> 100? "+ Contenttemp. length () +" n "+ contentStr );
}
Rsbody. append (beforCONTENT );
Rsbody. append (contenttemp );
Rsbody. append (endCONTENT );
Returns the real length of a string and the string function with a fixed length.
Function getInterceptedStr (sSource, iLen)
{
If (sSource. replace (/[^ x00-xff]/g, "xx"). length <= iLen)
{
Return sSource;
}
Var ELIDED = "";
Var str = "";
Var l = 0;
Var schar;
For (var I = 0; schar = sSource. charAt (I); I ++)
{
Str + = schar;
L ++ = (schar. match (/[^ x00-xff]/)! = Null? 2: 1 );
If (l> = iLen-ELIDED. length)
{
Break;
}
}
Str + = ELIDED;
Return str; |