基于这六个字符拆分字符串0102 **

时间:2014-03-14 12:44:55

标签: java java-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;
}

4 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:1)

String string = "blabla0102**dada";
String[] parts = string.split("0102\\*\\*");
String part1 = parts[0]; // blabla
String part2 = parts[1]; // dada

这里我们有一个字符串:&#34; blabla0102 ** dada&#34;,我们称之为字符串。每个String对象都有一个方法split(),使用它我们可以在任何我们想要的东西上分割一个字符串。

答案 2 :(得分:1)

现在我怀疑你忘了在分裂正则表达式中逃脱*

尝试一下

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

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

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

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

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

答案 3 :(得分:1)

你的意思是字面上被“0102 **”分开吗?你不能用正则表达式吗?

    String[] tokens = "My text 0102** hello!".split("0102\\*\\*");
    System.out.println(tokens[0]);
    System.out.println(tokens[1]);