java - 根据这六个字符分割字符串0102**

标签 java jakarta-ee

如何根据0102**分割扁平字符串?字符串分词器仅适用于 **。有没有办法根据0102**进行拆分?请推荐

这是我的完整方法

private String handleCibil(InterfaceRequestVO ifmReqDto, String szExtIntType) throws MalformedURLException, org.apache.axis.AxisFault, RemoteException {

    /* Declaration and initiliazation */
    ConfVO confvo = ifmReqDto.getExtConfVo();
    String szResponse = null;
    String cibilResponse = null;        
    String errorResponse = null;
    String endpointURL = null;
    long timeOut = confvo.getBurMgr().getBurInfo(szExtIntType).getTimeOut();
    endpointURL = formWebServiceURL(confvo, szExtIntType);
    URL url = new URL(endpointURL);



    log.debug("Input xml for cibil "+ifmReqDto.getIfmReqXML());
    BasicHttpStub stub= new BasicHttpStub(url,new org.apache.axis.client.Service());
   szResponse = stub.executeXMLString(ifmReqDto.getIfmReqXML());





    //szResponse=szResponse.replaceAll("&", "&");
     log.debug("szResponse "+szResponse);

    /* Validate if the obtained response is as expected by IFM */
    try {

        extDao = new ExtInterfaceXMLTransDAO(ifmReqDto.getSemCallNo(), ifmReqDto.getIdService());
        extDao.updateRqstRespXML10g(ifmReqDto.getInterfaceReqNum(), szResponse, GGIConstants.IFM_RESPONSE);

        //log.debug("CIBIL_RESPONSE_XPATH " + GGIConstants.CIBIL_RESPONSE_XPATH);
        Document xmlDocument = DocumentHelper.parseText(szResponse);
        String xPath = GGIConstants.RESPONSE_XPATH;
        List<Node> nodes = xmlDocument.selectNodes(xPath);
        for (Node node : nodes) {
            String keyValue = node.valueOf(GGIConstants.RESPONSE_XPATH_KEY);
           // log.debug("keyValue : " + keyValue);

            if (keyValue.equalsIgnoreCase(GGIConstants.RESPONSE_XPATH_KEY_VALUE)) {
             //   log.debug("node value  : " + node.getText());
                cibilResponse = node.getText();
            }
        }
        log.debug("cibilResponse " + cibilResponse);

        String errorResponseXPATH = GGIConstants.CIBIL_ERROR_RESPONSE_XPATH;
        List<Node> errorResponseNode = xmlDocument.selectNodes(errorResponseXPATH);
         for (Node node : errorResponseNode) {               
                errorResponse = node.getText();

        }
        log.debug("errorResponse " + errorResponse);

      if(cibilResponse!=null && cibilResponse.length()>0)
      {
           StringTokenizer cibilResponseResults = new StringTokenizer(cibilResponse,"**");

           String tempResponse="";
           ArrayList probableMatchList = new ArrayList();
            while (cibilResponseResults.hasMoreElements()) {

                tempResponse = (String) cibilResponseResults.nextElement();
                if(tempResponse.length()>=80)
                {   
                    String memberRefNo = tempResponse.substring(69, 80).replaceAll(" ", "");
                    log.debug("memberRefNo " + memberRefNo);

                    if (memberRefNo.length() > 0) {
                        if (Integer.parseInt(memberRefNo) > 0) {
                            cibilResponse = tempResponse;
                            cibilResponse = cibilResponse+"**";
                        }
                        else
                        {
                            probableMatchList.add(tempResponse+"**");
                        }
                    }
                    else
                    {
                        probableMatchList.add(tempResponse+"**");
                    }
                }
                else
                {
                    cibilResponse = tempResponse+"**";
                }
            }

            log.debug("After finding the Member reference number cibilResponse " + cibilResponse);
            log.debug("After finding the Probable reference list " + probableMatchList);
            // TKN 008 
        cibilResponse=StringEscapeUtils.unescapeXml(cibilResponse).replaceAll("[^\\x20-\\x7e]","");
            ifmReqDto.setIfmTransformedResult(cibilResponse);
            ifmReqDto.setProbableMatchList(probableMatchList);    
      }   
       if (errorResponse!=null && errorResponse.length()>0) {
            throw new GenericInterfaceException(errorResponse
                    + " for the seq_request " + ifmReqDto.getSeqRequest() + " Seq_Interface_req is >> "
                    + ifmReqDto.getInterfaceReqNum(),
                    GGIConstants.SEND_REQUEST_CONSTANT + Strings.padStart(String.valueOf(ifmReqDto.getIdService()), 2, GGIConstants.DEFAULT_NUMBER_STRING)
                    + GGIConstants.CIBIL_ERROR_CODE);
        }
       else if (cibilResponse==null || StringUtils.isEmpty(cibilResponse) ) {
            throw new GenericInterfaceException("Cibil TUEF response is empty >> cibil Service "
                    + "for the seq_request " + ifmReqDto.getSeqRequest() + "Seq_Interface_req is >> "
                    + ifmReqDto.getInterfaceReqNum(),
                    GGIConstants.SEND_REQUEST_CONSTANT + Strings.padStart(String.valueOf(ifmReqDto.getIdService()), 2, GGIConstants.DEFAULT_NUMBER_STRING)
                    + GGIConstants.INTERFACE_ERROR_RESPONSE);
        }
            /* Setting Instinct response to ifmReqDto object */
    } catch (SQLException e) {
        log.error("SQLException while connecting to DataBase. Exception message is  ", e);
        throw new GenericInterfaceException("SQLException >> Instinct Service "
                + "for the seq_request " + ifmReqDto.getSeqRequest() + "Seq_Interface_req is >> "
                + ifmReqDto.getInterfaceReqNum(),
                GGIConstants.SEND_REQUEST_CONSTANT + Strings.padStart(String.valueOf(ifmReqDto.getIdService()), 2, GGIConstants.DEFAULT_NUMBER_STRING)
                + GGIConstants.DB_OPERATION_ERROR);
    } catch (GenericInterfaceException exp) {
        log.error("Exception occured while valid:", exp);
        throw exp;

    } catch (Exception exp) {
        log.error("Exception occured while valid:", exp);
        throw new GenericInterfaceException("GeneralException >> Instinct Service "
                + "for the seq_request " + ifmReqDto.getSeqRequest() + "Seq_Interface_req is >> "
                + ifmReqDto.getInterfaceReqNum(),
                GGIConstants.SEND_REQUEST_CONSTANT + Strings.padStart(String.valueOf(ifmReqDto.getIdService()), 2, GGIConstants.DEFAULT_NUMBER_STRING)
                + GGIConstants.UNKNOWN_ERROR);

    }
    return szResponse;
}

最佳答案

我建议查看 Java documentation ,它提供了一个非常好的入门引用。 .split 方法使用正则表达式根据分隔符拆分字符串。

String[] tokens = myString.split("0102\\*\\*");

关于java - 根据这六个字符分割字符串0102**,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22405384/

相关文章:

java - 如何像在 Facebook 中那样在 JTextArea 中创建 Jlabel?

java - Android PDF Viewer空对象引用错误

java - Spring存储库按第一个实体进行选择并尝试映射到另一个实体(实体具有相同的名称)

java - 在 Java 中,什么时候应该在接口(interface)中使用抽象方法?

jakarta-ee - 如何实现容器管理事务(CMT)?

java - 用于在集合中递归存储类对象的数据结构java

java - 同时调用 2 个 Restful Web 服务。可以用骡子吗?

java - Web 实例已经停止

java - 如何将 map 转换为 url 查询字符串?

java - Hibernate 模板中的泛型问题