日期:2014-05-20  浏览次数:20606 次

一个字符处理题!
ScanSite
ScanType
SendSite
........

写一个方法将ScanSite 等字符 转换为 SCAN_SITE 等```
谁能帮个忙啊

------解决方案--------------------
答:参考代码:
Java code

public  static String ps(String s)
    {
        String rs=s.replaceAll("([A-Z])", "_$1");
        return s.charAt(0)=='_'?rs.toUpperCase():rs.substring(1).toUpperCase();
    }
    
    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub

        System.out.println("ScanSite=>"+ps("ScanSite")+"\n"+
                           "ScanType=>"+ps("ScanType")+"\n"+
                           "SendSite=>"+ps("SendSite"));
}