字符串的拆分以及分隔符所在不同位置的删除
try {?? ??? ??? ??? ??? ??? ??? ?//根據(jù)imComuserGroupMng獲取這個數(shù)據(jù)庫的所有ImComuserGroup數(shù)據(jù)
?? ??? ??? ??? ??? ??? ?List<ImComuserGroup> list = imComuserGroupMng.findAllComuserGroup();
?? ??? ??? ??? ??? ??? ?//便利實體數(shù)據(jù)list為數(shù)據(jù)的集合
?? ??? ??? ??? ??? ??? ?for (ImComuserGroup imComuserGroup : list) {
?? ??? ??? ??? ??? ??? ?//獲取實體的用戶ID其中ID是用分隔符|分割
?? ??? ??? ??? ??? ??? ??? ?String comUserId = imComuserGroup.getComUserId();
?? ??? ??? ??? ??? ??? ??? ?//轉(zhuǎn)化integer類型數(shù)據(jù)為字符串
?? ??? ??? ??? ??? ??? ??? ?String userId = ImCompactApply.getAuthUser().getUserId().toString();
?? ??? ??? ??? ??? ??? ??? ?//如果包含用戶的ID就進行字符串拆分的得到集合split 
?? ??? ??? ??? ??? ??? ??? ?if(comUserId.contains(userId)){
?? ??? ??? ??? ??? ??? ??? ??? ?String[] split = comUserId.split("\\|");
?? ??? ??? ??? ??? ??? ??? ??? ?String replace = "";
?? ??? ??? ??? ??? ??? ??? ??? ?//判斷集合長度
?? ??? ??? ??? ??? ??? ??? ??? ?if(split.length>1){
?? ??? ??? ??? ??? ??? ??? ??? ?判斷集合是否為要刪除的用戶的ID開始例如:1|2|3要刪除1加|
?? ??? ??? ??? ??? ??? ??? ??? ??? ?if(comUserId.startsWith(userId+"|")){
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?replace = comUserId.replace(userId+"|", "");
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?imComuserGroup.setComUserId(replace);
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?imComuserGroupMng.update(imComuserGroup);
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?集合是否為要刪除的用戶的ID結(jié)束例如:3|2|1要刪除|加1
?? ??? ??? ??? ??? ??? ??? ??? ??? ?}if(comUserId.endsWith("|"+userId)){
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?replace = comUserId.replace("|"+userId, "");
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?imComuserGroup.setComUserId(replace);
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?imComuserGroupMng.update(imComuserGroup);
?? ??? ??? ??? ??? ??? ??? ??? ??? ?}else{
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?判斷集合是否為中間如2|1|3刪除1
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?replace = comUserId.replace(userId+"|", "");
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?imComuserGroup.setComUserId(replace);
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?imComuserGroupMng.update(imComuserGroup);?? ?
?? ??? ??? ??? ??? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ??? ??? ??? ?}else{
?? ??? ??? ??? ??? ??? ??? ??? ??? ?判斷集合要刪除的數(shù)據(jù)是長度為1直接刪除整個實體
?? ??? ??? ??? ??? ??? ??? ??? ??? ?replace = comUserId.replace(userId, "");
?? ??? ??? ??? ??? ??? ??? ??? ??? ?imComuserGroup.setComUserId(replace);
?? ??? ??? ??? ??? ??? ??? ??? ??? ?imComuserGroupMng.deleteById(imComuserGroup.getId());
?? ??? ??? ??? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?} catch (Exception e) {
?? ??? ??? ??? ??? ??? ?
?? ??? ??? ??? ?}
轉(zhuǎn)載于:https://www.cnblogs.com/gongzh/p/8594916.html
總結(jié)
以上是生活随笔為你收集整理的字符串的拆分以及分隔符所在不同位置的删除的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 支付宝信用卡办理在哪里?手把手教你支付宝
 - 下一篇: 交通银行高达主题信用卡年费多少?年费可以