/** * 项目名称: * 文件说明: ExCEL公式类型:字符串公式 * 主要特点: * 版本号:1.0 * 制作人:刘晨曦 * 创建时间:2013-12-3 **/ package EXCEL; /** * @author lcx * */ public class StringFunctions { public static String right(String str,int len) { if(len>str.length()) throw new IllegalArgumentException("截取长度不能大于数组长度"); return str.substring(str.length()-len, str.length()); } public static String left(String str,int len) { if(len>str.length()) throw new IllegalArgumentException("截取长度不能大于数组长度"); return str.substring(0, len); } public static String mid(String str,int start,int len) { if(start+len-1>str.length()) throw new IllegalArgumentException("截取越限"); return str.substring(start-1, start+len-1); } public static int len(String str) { if(str==null) return 0; return str.length(); } public static String concatenate(String...strs) { StringBuffer buffer=new StringBuffer(); for(String str:strs) buffer.append(str); return buffer.toString(); } public static boolean exact(String str1,String str2) { return str1.equals(str2); } public static String upper(String str1) { if(str1==null) return ""; return str1.toUpperCase(); } public static int find(String find_text,String within_text,int start_num) { if(start_num<=0||start_num>within_text.length()) throw new IllegalArgumentException("start_num参数输入问题"); if(find_text.length()>within_text.length()) return -1; String tag=within_text.substring(start_num-1); int index=tag.indexOf(find_text); if(index<0) return -1; return index+start_num; } public static void main(String[] args) { /*******************测试字符串*****************************/ System.out.println(mid("我想要编程",2,2)); System.out.println(left("我想要编程",2)); System.out.println(right("我想要编程",3)); System.out.println(concatenate("a","b","c","d")); System.out.println(exact(new String("aaa"),new String("aaa"))); System.out.println(upper("aaaa")); System.out.println(find("b","abcabc",3)); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/u011680348/article/details/47661393