如何在下面的场景中操作java中的字符串

"\r\n\r\n\r\n\r\nCovered. Coverage is limited to a one-time only 7095 for one outpatien" +

"t in vitro fertilization procedure while you are an 7095 member.  If you receive" +

" 7095s for in vitro fertilization services under an 7095 plan, you will not b" +

"e eligible for in vitro fertilization 7095s under any other 7095 plan. In vit" +

"ro fertilization services are not covered when a surrogate is used.  The in vitr" +

"o procedures must be performed at a medical facility that conforms to the Americ" +

"an College of Obstetricians and Gynecologists’ guidelines for in vitro fertiliza" +

"tion clinics or to the American Society for Reproductive Medicine’s minimal stan" +

"dards for programs of in vitro fertilization. \r\n\r\n\r\n\r\n\r\nIf you have a male partn" +

"er, you must meet all of the following criteria:\r\n•   You and your male partner " +

" have a five-year history of infertility or infertility is related to one or mor" +

"e of the following medical conditions: \r\n–         Endometriosis; \r\n–         Ex" +

我想用具有以下限制的空字符串替换上面字符串中的 /r/n 。1. 如果 /r/n 只存在一次,则不要替换它(例如:/r/n) 2. 如果多个 /r/n 则替换(例如:/r/n/r/n/r/n/r /n 然后用空字符串替换。


示例字符串 "\r\n\r\n\r\n\r\nCovered。覆盖范围仅限于\r\n 一名门诊患者一次仅 7095\r\n\r\n\r\n" ;


预期产出:覆盖。承保范围仅限于\r\n 一名门诊患者一次性仅 7095


侃侃无极
浏览 128回答 1
1回答

森林海

我会写这样的东西:my_str = my_str.replaceAll("(\r\n){2,}", "");希望有帮助。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java