java 替换字符串数组_Java工具类--拆分字符串组装数组,替换字符

Java工具类--拆分字符串组装数组,替换字符

/**

* 拆分字符串获取Ids

*

* @param idsString id字符串

* @param spiltCode 拆分符号

* @return ids

* @author lqy

*/

@Bizlet()

public static int[] getIdsAfterSpilt(String idsString, String spiltCode){

List idList = new ArrayList();

if(idsString == null || idsString.trim().equals("")){

return null;

}else{

if(spiltCode == null || spiltCode.trim().equals("")){

spiltCode = ",";

}

String[] idArray = idsString.split(spiltCode);

if(idArray != null && idArray.length > 0){

for (String string : idArray) {

if(string != null && !string.trim().equals("")){

idList.add(Integer.parseInt(string.trim()));

}

}

}

}

if(idList != null && idList.size() > 0){

int[] ids = new int[idList.size()];

for (int j=0;j

ids[j] = idList.get(j);

}

return ids;

}

return null;

}

/**

* 删除字符串最后一位

*

* @param str 字符串

* @return str

* @author lqy

*/

@Bizlet()

public static String removeLastCode(String str) {

if(str == null || str.trim().equals("")){

str = "";

}else{

str = str.trim().substring(0, (str.trim().length()-1));

}

return str;

}

/**

* 替换字符

*

* @param str 字符串

* @param oldCode 需要替换的原字符

* @param newCode 替换的新字符

* @return str

* @author lqy

*/

@Bizlet()

public static String replaceCode(String str, String oldCode, String newCode) {

if(str != null && !str.trim().equals("")){

if(oldCode == null || oldCode.trim().equals("")){

oldCode = " ";

}

if(newCode == null){

newCode = "";

}

str = str.trim().replaceAll(oldCode, newCode);

}

return str;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值