Re: how to fill the string to length = 256



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();

}

}

"Roedy Green" <look-on@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:pmehe1lkahp35sbf1d04a8e8hrosu269tt@xxxxxxxxxx
> On Thu, 28 Jul 2005 13:29:33 +0800, <moon_ils-se@xxxxxxxxxxxx> wrote
> or quoted :
>
> >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
>
> --
> 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


.



Relevant Pages

  • Re: How create a console using java graphical interface
    ... public final static int WARNING = 1; ... @param severity Severity of error: ... String s) ... @param s string to log. ...
    (comp.lang.java.programmer)
  • Re: flush the content of a TextArea?
    ... public final static int WARNING = 1; ... * @param severity Severity of error: ... String s) ... * @param s string to log. ...
    (comp.lang.java.programmer)
  • Re: Html download challenge
    ... >seems to know I am not a browser. ... * @return String of currency codes wanted, ... * @param result Results to save, ... int statusCode; ...
    (comp.lang.java.programmer)
  • Re: Regular Expression taking excessive CPU
    ... > regular expression adding so much time to the process, ... > ftIndex is a string variable that typically won't exceed 100 characters. ... static string RemoveNonAlpha1 ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: JSpinner in hex
    ... public class HexNumberEditor extends JSpinner.NumberEditor { ... @param spinner JSpinner this editor is attached to. ... public HexNumberEditor(JSpinner spinner, int width) ... Converts the passed in String into an instance of ...
    (comp.lang.java.gui)