Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2005

Tip: Looking for answers? Try searching our database.

how to fill the string to length = 256

Thread view: 
moon_ils-se@yahoo.com.hk - 28 Jul 2005 06:29 GMT
Now, I am using below code, how to fill the string to length = 256 or more ?
    inputLine = inputLine.substring(0,inputLine.length())  +
    "                                                        " +
    "                                                        " +
    "                                                        "

/*  decode 23.18.14

javac decode_mrp.java

*/
import java.io.*;

public class decode_mrp {
public static void main(String[] args) throws IOException {
String inputLine , outputLine;
String item,site;
  BufferedReader in
     = new BufferedReader(new FileReader(args[0]));

  while ((inputLine = in.readLine()) != null) {

    inputLine = inputLine.substring(0,inputLine.length())  +
    "                                                        " +
    "                                                        " +
    "                                                        "
    ;
     // System.out.println(inputLine.substring(2,14) + "<");
      if (inputLine.substring(2,14).equals("Item Number:")) {
       item = inputLine.substring(15,29);
       site = inputLine.substring(121,129 );
       System.out.println(item + " " + site);

    }
  }

}

}
Roedy Green - 28 Jul 2005 12:00 GMT
>Now, I am using below code, how to fill the string to length = 256 or more ?
>     inputLine = inputLine.substring(0,inputLine.length())  +
>     "                                                        " +
>     "                                                        " +
>     "          

   /**
    * Pads the string out to the given length by applying blanks on
the left.
    *
    * @param s
    *        String to be padded/chopped.
    * @param newLen
    *        length of new String desired.
    * @param chop
    *        true if Strings longer than newLen should be truncated
to newLen
    *        chars.
    * @return String padded on left/chopped to the desired length.
    */
   public final static String leftPad ( String s, int newLen, boolean
chop )
       {
       int grow = newLen - s.length();
       if ( grow <= 0 )
           {
           if ( chop )
               {
               return s.substring( 0, newLen );
               }
           else
               {
               return s;
               }
           }
       else if ( grow <= 30 )
           {
           return "                              ".substring( 0, grow
) + s;
           }
       else
           {
           return rep( ' ', grow ) + s;
           }
       } // end leftPad

 /**
    * Produce a String of a given repeating character.
    *
    * @param c
    *        the character to repeat
    * @param count
    *        the number of times to repeat
    * @return String, e.g. rep('*',4) returns "****"
    */
   public final static String rep ( char c, int count )
       {
       char[] s = new char[ count ];
       for ( int i = 0; i < count; i++ )
           {
           s[ i ] = c;
           }
       return new String( s ).intern();
       } // end rep

Signature

Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes

moon_ils-se@yahoo.com.hk - 29 Jul 2005 03:56 GMT
Thank. It works

public final class test_string {
public static void main(String[] args)  {
 String s = new String("eric");
 s = s + rep(' ',10) + "<";
 System.out.println(s);
}

public static String rep(char c, int count) {
       char[] s = new char[count];
       for (int i = 0; i< count ; i++) {
            s[i] = c;
       }
       return new String(s).intern();

}

}

> >Now, I am using below code, how to fill the string to length = 256 or more ?
> >     inputLine = inputLine.substring(0,inputLine.length())  +
[quoted text clipped - 68 lines]
> Canadian Mind Products, Roedy Green.
> See http://mindprod.com/iraq.html photos of Bush's war crimes


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.