skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Sunday, October 14, 2012

Code to wrap String to number of Characters

Posted by Raju Gupta at 3:03 AM – 0 comments
 

This method is used to wrap the input parameter based on the wrapLength
If the length of the input string is greater than the wrapLength the
input string is truncated to the length of wrapLength and the last 3
characters are replaced with "..."


public static String wrapNameFields(String inputStr, int wrapLength) {
  StringBuffer wrapString = new StringBuffer();
  if (iinputStr != null && inputStr.equals("") == false) {
   if (inputStr.length() > wrapLength) {
    wrapString.append(inputStr.substring(
      0, wrapLength
      - "..."length()));
    wrapString.append("...");
   } else {
    wrapString.append(inputStr);
   }
  }
  return wrapString.toString();
}


Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger