Substring
public string substring (int beginindex) returns a new string that is a substring of this string. The substring starts at the specified index and continues to 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 (including) at the beginning.
Return:
The specified substring.
Thrown:
Indexoutofboundsexception-if beginindex is negative or greater than the length of this String object
Cases
/*
* Content too long may cause XML files to be too large to load too slowly.
* But from the perspective of SEO to consider all the output is beneficial to the search engine, but generally the content will not be too much
* In order to prevent the space line wrapping CSS can not control the large page, with regular expressions to replace the space, so the first 100 characters, the content of the page display with CSS control
*zdz works, the works of the wind
Code to copy code as follows
*/
Str.trim (). ReplaceAll ("\s+", "" ");
String contenttemp = rs.getstring (ContentName). Trim (). ReplaceAll ("\s+", "");
Npfdebug.print (Contenttemp.length ());
if (Conten (www.111cn.net) ttemp.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);
Get string real length and fixed length string function
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;
From:http://www.111cn.net/jsp/java/46329.htm
Java Intercept String functions