Java Intercept String functions

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.