Java tutorial
//package com.java2s; // This source is subject to the Microsoft Public License (Ms-PL) public class Main { public static String getWCFTypeText(String fullyQualifiedClassName) { return getClassName(fullyQualifiedClassName) + ":#" + getPackageName(fullyQualifiedClassName); } public static String getClassName(Object o) { String fullyQualifiedClassName = o.getClass().getName(); return getClassName(fullyQualifiedClassName); } public static String getClassName(String fullyQualifiedClassName) { int firstChar; String className = fullyQualifiedClassName; firstChar = fullyQualifiedClassName.lastIndexOf('.') + 1; if (firstChar > 0) { className = className.substring(firstChar); } return className; } public static String getPackageName(Class<?> c) { String fullyQualifiedName = c.getName(); return getPackageName(fullyQualifiedName); } public static String getPackageName(String fullyQualifiedClassName) { int lastDot = fullyQualifiedClassName.lastIndexOf('.'); if (lastDot == -1) { return ""; } return fullyQualifiedClassName.substring(0, lastDot); } }