Last active
December 28, 2015 12:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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