strip indent in groovy multiline strings

后端 未结 7 870
名媛妹妹
名媛妹妹 2020-12-08 13:49

Unfortunately stripIndent on a multiline string does not work. Side note: My IDE code style preferences allow only space indentation (tabs will be replaced by spaces). But i

相关标签:
7条回答
  • 2020-12-08 14:17

    stripMargin() is to strip leading spaces from lines with margin.

    Default margin is |. We can also specify a custom margin.

    For example,

    def s = """*This 
            *is
                *multiline
    """
    
    println(s.stripMargin("*"))
    

    will result in

    This 
    is
    multiline
    

    The best practice is that we append .trim() in the end to eliminate leading and trailing spaces of the whole string.

    For example,

    println(s.stripMargin("*").trim())
    
    0 讨论(0)
提交回复
热议问题