dsnrixf6765 2019-04-30 03:30
浏览 23
已采纳

删除特定字符串之间的空格

I need to remove whitespace between </Listing> and <Listing> inside a file.

I looked here:

How to trim leading and trailing white spaces of a string?

But that is not string specific.

  • 写回答

1条回答 默认 最新

  • douqian6315 2019-04-30 12:51
    关注

    If you're munging nested/structured data like XML I'd strongly suggest using a real XML parser.

    But just using a regexp it isn't too hard:

    r := regexp.MustCompile(`(?m:</Listing>\s*<Listing>)`)
    var s string = "</Listing><Listing>"
    fmt.Println(r.ReplaceAllString("</Listing>  
    
     <Listing>", s))
    

    Note the ?m regexp flag to enabled multi-line matching (assuming you want to allow </Listing> and <Listing> to be on separate lines

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突