1 23 24 29 30 package com.sun.enterprise.tools.common.util; 31 32 37 public class StringUtils 38 { 39 public static String UpperCaseFirstLetter(String s) 40 { 41 if(s == null || s.length() <= 0) 42 return s; 43 44 return s.substring(0, 1).toUpperCase() + s.substring(1); 45 } 46 47 49 public static String padRight(String s, int len) 50 { 51 if(s == null || s.length() >= len) 52 return s; 53 54 for(int i = len - s.length(); i > 0; --i) 55 s += ' '; 56 57 return s; 58 } 59 60 61 63 public static String padLeft(String s, int len) 64 { 65 if(s == null || s.length() >= len) 66 return s; 67 68 String ret = ""; 70 for(int i = len - s.length(); i > 0; --i) 71 ret += ' '; 72 73 return ret + s; 74 } 75 76 78 public static String toShortClassName(String className) 79 { 80 int index = className.lastIndexOf('.'); 81 82 if(index >= 0 && index < className.length() - 1) 83 return className.substring(index + 1); 84 85 return className; 86 } 87 88 90 public static String replace(String s, String token, String replace) 91 { 92 if(s == null || s.length() <= 0 || token == null || token.length() <= 0) 93 return s; 94 95 int index = s.indexOf(token); 96 97 if(index < 0) 98 return s; 99 100 int tokenLength = token.length(); 101 String ret = s.substring(0, index); 102 ret += replace; 103 ret += s.substring(index + tokenLength); 104 105 return ret; 106 } 107 108 110 public static void main(String [] args) 111 { 112 String [] test = new String [] { "xyz", "HITHERE", "123aa", "aSSS", "yothere" }; 114 for(int i = 0; i < test.length; i++) 115 { 116 System.out.println(test[i] + " >>> " + UpperCaseFirstLetter(test[i])); } 118 } 119 public static boolean isEmpty(String s) 120 { 121 if((s != null) && (! s.trim().equals(""))) { 123 return false; 124 }else 125 { 126 return true; 127 } 128 } 129 130 131 } 132 | Popular Tags |