cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
lala
Level VII

How can count the number of consecutive Spaces at the beginning of each line?

It can be implemented with a formula or a regex

2024-05-08_10-35-26.png
I only know how to use this formula, but it's definitely not right.I don't want to do it in a circular way.

Length(txt)-Length(Substitute(txt, " ", ""))

Thanks!

3 REPLIES 3
lala
Level VII

回复: How can count the number of consecutive Spaces at the beginning of each line?

          Scripting Guide
              Introduction to Writing JSL Scripts
                  What JSL Can Do for You
                  Help with Learning JSL
                      The Scripting Index
                      Let JMP Teach You JSL
                  JSL Terminology
                  Basic JSL Syntax
                  Scripting Guide Conventions
              Get Started
                  Capture a Script for an Analysis Report
                  Capture a Script for a Data Table
                  Capture a Script to Import a File
                  Glue Scripts Together
txnelson
Super User

Re: How can count the number of consecutive Spaces at the beginning of each line?

This is similar to your code, but I would suspect it will more correct, because your code will substitute the blank characters within the text.

txt = "   Scripting Guide";
numLeadingBlanks = Length( txt ) - Length( Trim( txt ) );

It can also return an error if there are trailing blanks.

This should correct for that issue

txt = "   Scripting Guide   ";
numLeadingBlanks = Contains( txt, Substr( Trim( txt ), 1, 1 ) ) - 1;
Jim
jthi
Super User

Re: How can count the number of consecutive Spaces at the beginning of each line?

You can also provide Trim() with optional argument left (it defaults to both) so it trims only start of the string

txt = "   Scripting Guide   ";
numLeadingBlanks = Length(txt) - Length(Trim Whitespace(txt, left));

(Trim Whitespace() should just be an alias for same function but it is more clear so I tend to use it)

-Jarmo