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;
}

最佳答案

现在,我怀疑您忘记了在拆分正则表达式中转义*的方法。

尝试也许

String[] resutl = yourString.split("0102\\*\\*");




如果您希望*代表任何字符,请使用.代替*

String[] resutl = yourString.split("0102..");




如果您希望*代表任何数字,请改用\\d

String[] resutl = yourString.split("0102\\d\\d");

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

相关文章:

java - 如何以线程安全的方式在 DAO 中缓存信息

java - 如何为具有泛型方法的功能接口(interface)创建 lambda 表达式

linux - vraptor/weld项目仅适用于Mac

java - 使用 JdbcUserDetailsManager 与自己的 UserDetailsS​​ervice

java - 调用 servlet 时不转发

java - Spring 与 Hibernate 映射到数据库 View

java - 带有 RESTeasy : automatic scanning of resources? 的 JAX-RS

java - 在外接圆的中心显示标记

java - JAX-RS Web 应用程序中的 Apache CXF OAuthDataProvider

jakarta-ee - 如何从Eclipse中排除Maven测试范围的依赖项(但将其保留在单元测试的路径中)