JAVA实现EXCEL公式专题(四)——字符串函数直接上代码:
/**
* 项⽬名称:
* ⽂件说明: 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())
字符串长度函数excelthrow 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 strs)
{
StringBuffer buffer=new StringBuffer();
for(String str:strs)
buffer.append(str);
String();
}
public static boolean exact(String str1,String str2)
{
return str1.equals(str2);
}
public static String upper(String str1)
{
if(str1==null)
return "";
UpperCase();
}
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));
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论