Java - Write code to Clean the generated alias by removing any non-alpha characters from the beginning.

Requirements

Write code to Clean the generated alias by removing any non-alpha characters from the beginning.

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String alias = "12312book2s.com";
        System.out.println(cleanAlias(alias));
    }/*from   w ww.  j a v  a  2 s  .co  m*/

    /**
     * Clean the generated alias by removing any non-alpha characters from the
     * beginning.
     *
     * @param alias The generated alias to be cleaned.
     * @return The cleaned alias, stripped of any leading non-alpha characters.
     */
    private static String cleanAlias(String alias) {
        char[] chars = alias.toCharArray();
        if (!Character.isLetter(chars[0])) {
            for (int i = 1; i < chars.length; i++) {
                if (Character.isLetter(chars[i])) {
                    return alias.substring(i);
                }
            }
        }
        return alias;
    }
}