Skip to content

Instantly share code, notes, and snippets.

@donpandix
Last active December 28, 2015 12:48
Show Gist options
  • Save donpandix/508e15ca98449fb34b1f to your computer and use it in GitHub Desktop.
Save donpandix/508e15ca98449fb34b1f to your computer and use it in GitHub Desktop.
String Pad Left, función para llenar con un caracter el lado izquierdo de una cadena de un largo mínimo
public class Fn {
public static String strpadLeft ( String cadena, String caracter, int largo ) {
if ( cadena.length() < largo ) {
largo -= cadena.length();
while ( largo-- > 0) {
cadena = caracter + cadena;
}
}
return cadena;
}
}
// Uso de la función
// String cadena = Fn.strpadLeft ("HOLA", "!", 10);
// System.out.println( cadena );
// Imprime por consola !!!!!!HOLA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment