Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {

    public static String normalizeName(String strName) {
        if (strName == null)
            return null;
        if (strName.length() == 0)
            return strName;

        char[] strChars = strName.toCharArray();
        char firstChar = strName.charAt(0);
        if (!(((firstChar >= 'a') && (firstChar <= 'z')) || ((firstChar >= 'A') && (firstChar <= 'Z'))
                || (firstChar == '_'))) {
            strChars = strName.toCharArray();
            strChars[0] = '_';
        }

        int len = strName.length();
        for (int i = 1; i < len; i++) {
            char c = strName.charAt(i);
            if (!(((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= '0') && (c <= '9'))
                    || (c == '_') || (c == '-'))) {
                if (strChars == null)
                    strChars = strName.toCharArray();
                strChars[i] = '_';
            }
        }
        if (strChars == null)
            return strName;
        else
            return new String(strChars);
    }
}