基于某些值在java中拆分字符串

时间:2013-10-03 07:29:49

标签: java regex string replace

我有以下字符串:

String verifyPaymentDetails = "{
2298597={mihpayid=403993715508098532, request_id=NULL, bank_ref_num=NULL, amt=53.77, disc=0.00,   mode=CC, PG_TYPE=AXIS, card_no=512345XXXXXX2346, name_on_card=emu, udf2=0, addedon=2013-06-03 17:34:42, status=failure, unmappedstatus=failed, Merchant_UTR=NULL, Settled_At=NULL}, 
6503939={mihpayid=Not Found, status=Not Found}
}"

我希望拆分字符串并获取像2298597={mihpayid=403993715508098532, request_id=NULL, bank_ref_num=NULL, amt=53.77, disc=0.00, mode=CC, PG_TYPE=AXIS, card_no=512345XXXXXX2346, name_on_card=emu, udf2=0, addedon=2013-06-03 17:34:42, status=failure, unmappedstatus=failed, Merchant_UTR=NULL, Settled_At=NULL},这样的值,如何在java中使用string.split?

并且在拆分值之后,我将值替换为{}

请帮助您做到这一点。

感谢

1 个答案:

答案 0 :(得分:1)

尝试

String verifyPaymentDetails = "{"
    + "2298597={mihpayid=403993715508098532, request_id=NULL, bank_ref_num=NULL, amt=53.77, disc=0.00,   mode=CC, PG_TYPE=AXIS, card_no=512345XXXXXX2346, name_on_card=emu, udf2=0, addedon=2013-06-03 17:34:42, status=failure, unmappedstatus=failed, Merchant_UTR=NULL, Settled_At=NULL},"
    + "6503939={mihpayid=Not Found, status=Not Found}" + "}";
String[] split = verifyPaymentDetails.substring(1,
    verifyPaymentDetails.length() - 2).split("(\\}, ?|=\\{)");