Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

counting spaces before first character

Status
Not open for further replies.

terpster73

IS-IT--Management
Feb 4, 2008
19
US
Is there a way for me to count the number of spaces before the first character in a row?

We are receiving files that have parent and child accounts and the only way to tell that it's a child account is that it's indented.

thanks.
 



Hi,

how about length minus trim length?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Code:
SELECT LEN(YourField) - LEN(LTRIM(YourField)) AS LeadingSpaces
       FROM YourTable

NOT TESTED!

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
You could try...

Code:
Declare @Temp Table(Data VarChar(50))

Insert Into @Temp Values('No Indent')
Insert Into @Temp Values('  A Little Indent')
Insert Into @Temp Values('         A Lot Indent')

Select *, PatIndex('%[^ ]%', Data) From @Temp

This code, with PatIndex, will return the character position of the first Non-Space character.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
O! forgot:
Code:
SELECT PATINDEX('[^ ]%', YourField)-1 AS LeadingSpaces
       FROM YourTable
Again: NOT TESTED! :)

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top