How Many Lines in String?

WJG (04/10/25) A simple enough question I suppose, with a simple solution.

set str "Line 1.\nLine 2.\nLine 3."
puts [llength [split $str \n]] 

If str is surrounded by whitespace, then best delete it to get a more accurate result based upon readable text.

set str "\nLine 1.\nLine 2.\nLine 3.\n"
puts [llength [split [string trim $str] \n]]