Rich Uchytil
Rich Uchytil

Reputation: 509

SSRS - Count elements in a delimited string

Say I have this string: "1/r/5/dfg/998". There are five elements delimited by a "/". I'm looking for the simplest way to count the number of elements in that string in SSRS and would prefer not to write a custom code function.

I know in SSRS split will make an array out of this string and I can use GetUpperBound(0) like this:

split("1/r/5/dfg/998","/").GetUpperBound(0)

The problem is this returns 4 not 5. If there was a "/" at the end of the string it would return 5. So I need to check for that and add 0 or 1 like so:

split("1/r/5/dfg/998","/").GetUpperBound(0) + iif(right("1/r/5/dfg/998",1) = "/",0,1)

That will give me 5. Is there a simpler way to do this? I wish I could just do

count(split("1/r/5/dfg/998","/"))

but that gives me an error. Thanks for any suggestions!

Upvotes: 0

Views: 3693

Answers (1)

Rich Uchytil
Rich Uchytil

Reputation: 509

Just found it while googling and trying different things:

split("1/r/5/dfg/998","/").Length

That's perfect!

Upvotes: 7

Related Questions