470,600 Members | 1,466 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,600 developers. It's quick & easy.

Quantify items in a string

OK, I have a string that reads like this:

[Group1][Group3][Group3]...[Group10]

How do I quantify how many[*] occurences there are in classic ASP? Do
i use the inStr function and if so, how???

Here's my thought process...

if groups > 1 then
do this
else 'more than 1 group present
do that
end if

But how do I loop through the string and quantify how many groups
there are using the above string?

Thanks in advance!
Jul 19 '05 #1
5 1474
If a group is signified by ending in a "]" then you can do this:

groupString = "[Group1][Group2][Group3]"
Response.Write len(GroupString) - len(replace(GroupString, "]", "")) & "
groups."

You could also do this:

groupString = "[Group1][Group2][Group3]"
Response.Write (ubound(split(groupString, "][")) + 1) & " groups."

"Sans Spam" <sa*******@yahoo.com> wrote in message
news:18**************************@posting.google.c om...
OK, I have a string that reads like this:

[Group1][Group3][Group3]...[Group10]

How do I quantify how many[*] occurences there are in classic ASP? Do
i use the inStr function and if so, how???

Here's my thought process...

if groups > 1 then
do this
else 'more than 1 group present
do that
end if

But how do I loop through the string and quantify how many groups
there are using the above string?

Thanks in advance!

Jul 19 '05 #2
On 17 Nov 2003 14:30:30 -0800, sa*******@yahoo.com (Sans Spam) wrote:
OK, I have a string that reads like this:

[Group1][Group3][Group3]...[Group10]

How do I quantify how many[*] occurences there are in classic ASP? Do
i use the inStr function and if so, how???

Here's my thought process...

if groups > 1 then
do this
else 'more than 1 group present
do that
end if

But how do I loop through the string and quantify how many groups
there are using the above string?

Thanks in advance!


If your spec is exactly as shown, I would say to use the split
operator using the string "][" as a seperator.

dim a, groupcount
a = split("[Group1][Group3][Group9]", "][")
groupcount = ubound(a) + 1

would give you an array of 3 items.

a(0) = "[Group1"
a(1) = "Group3"
a(2) = "Group9]"

groupcount would equal 3.

Jul 19 '05 #3
"Sans Spam" <sa*******@yahoo.com> wrote in message
news:18**************************@posting.google.c om...
OK, I have a string that reads like this:

[Group1][Group3][Group3]...[Group10]

How do I quantify how many[*] occurences there are in classic ASP? Do
i use the inStr function and if so, how???

Here's my thought process...

if groups > 1 then
do this
else 'more than 1 group present
do that
end if

But how do I loop through the string and quantify how many groups
there are using the above string?

Thanks in advance!


<script language="JavaScript" runat="SERVER">
Response.Write("[Group1][Group2][Group3]".match(/\[.*?\]/g).length);
</script>

-Chris Hohmann
Jul 19 '05 #4
On Mon, 17 Nov 2003 15:26:48 -0800, "Chris Hohmann"
<no****@thankyou.com> wrote:
"Sans Spam" <sa*******@yahoo.com> wrote in message
news:18**************************@posting.google. com...
OK, I have a string that reads like this:

[Group1][Group3][Group3]...[Group10]

How do I quantify how many[*] occurences there are in classic ASP? Do
i use the inStr function and if so, how???

Here's my thought process...

if groups > 1 then
do this
else 'more than 1 group present
do that
end if

But how do I loop through the string and quantify how many groups
there are using the above string?

Thanks in advance!


<script language="JavaScript" runat="SERVER">
Response.Write("[Group1][Group2][Group3]".match(/\[.*?\]/g).length);
</script>


I knew I should have looked at the regular expression method :)

Jul 19 '05 #5
"Dan Brussee" <db******@nc.rr.com> wrote in message
news:hm********************************@4ax.com...
On Mon, 17 Nov 2003 15:26:48 -0800, "Chris Hohmann"
<no****@thankyou.com> wrote:
"Sans Spam" <sa*******@yahoo.com> wrote in message
news:18**************************@posting.google. com...
OK, I have a string that reads like this:

[Group1][Group3][Group3]...[Group10]

How do I quantify how many[*] occurences there are in classic ASP? Do i use the inStr function and if so, how???

Here's my thought process...

if groups > 1 then
do this
else 'more than 1 group present
do that
end if

But how do I loop through the string and quantify how many groups
there are using the above string?

Thanks in advance!


<script language="JavaScript" runat="SERVER">
Response.Write("[Group1][Group2][Group3]".match(/\[.*?\]/g).length);
</script>


I knew I should have looked at the regular expression method :)


Yeah, RE's are pretty sexy. Although, for small input strings like this,
the Replace function is actually faster. With RegExp, there's the object
implementation to contend with. However, the RegExp object scales much
better, so for large input (i.e. files), RE's are the way to go. RE's
are also much more powerful. Try validating email addresses with
Left/Right/InStr/Len, then try doing it with RE's. You'll never look
back. Give me an regular expression engine and a looping construct and
I'll rule the world.

-Chris Hohmann
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Joerg Schuster | last post: by
reply views Thread by Islam Elkhayat | last post: by
3 posts views Thread by Achava Nakhash, the Loving Snake | last post: by
13 posts views Thread by PetterL | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.