Over a million developers have joined DZone.

Format Code With Line Numbers In Markdown Notation

·

C:\>type Format.groovy | groovy Format
     1: def counter = 1
     2:
     3: System.in.eachLine {
     4:         line ->
     5:
     6:         def result = "    "
     7:         (2 - ("" + counter).length()).times { result += " " }
     8:         result += "${counter}: ${line}"
     9:         println result
    10:         counter++
    11: }

C:\>



def counter = 1

System.in.eachLine {
	line ->
	
	def result = "    "
	(2 - ("" + counter).length()).times { result += " " }
	result += "${counter}: ${line}"
	println result
	counter++
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}