Java tutorial
//package com.java2s; public class Main { private static final String PATTERN = "^[A-Za-z0-9]+$"; private static final String SHARP = "#"; public static String getFirst(String pinyin) { if (pinyin == null || pinyin.length() < 1) { return SHARP; } String fistLetter = pinyin.substring(0, 1); if (!fistLetter.matches(PATTERN)) { return SHARP; } return fistLetter; } }