?
Solved

Can someone show me how to using any string function to check how many capital letters in this string.

Posted on 2005-04-05
7
Medium Priority
?
238 Views
Last Modified: 2008-02-01
Hi, i have a string - "PeterKJohnson"

Can someone show me how to use any string functions to check how many capital letters in this string, then separate them into 3 substring.  Peter, K and Johnson
0
Comment
Question by:musclejack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 13710043
Here you go:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<script language=vbscript>
function howMany(strToQuery)
      dim intCaps
      intCaps = 0
      for i=1 to len(strToQuery)
            if Mid(strToQuery, i, 1) = UCase(Mid(strToQuery, i, 1)) then
                  intCaps = intCaps + 1
            end if
      next
      howMany = intCaps
end function

sub showMe()
      msgbox howMany("PeterKJohnson")
end sub
</script>
</head>

<body onLoad="showMe()">

</body>
</html>
0
 
LVL 8

Expert Comment

by:hendridm
ID: 13710297
Very crude:

<%
Function SplitIt(str)
   Dim arr(), tmp
   counter = 0

   For i = 1 to Len(str)
      s = Mid(str, i, 1)
      If (ASC(s) >= 65 And ASC(s) <= 90) And (i > 1) Then
             counter = counter + 1
             Redim Preserve arr(counter)
             arr(counter) = tmp
             tmp = s
      Else
             tmp = tmp & s
      End If
   Next

   counter = counter + 1
   Redim Preserve arr(counter)
   arr(counter) = tmp

   SplitIt = arr
End Function
%>

<html><body>

<h3>Results</h3>

<%
NameArray = SplitIt("PeterKJohnson")

For k = 1 to UBound(NameArray)
      Response.Write "Part " & k & ": " & NameArray(k) & "<br>"
Next
%>

</html></body>
0
 
LVL 8

Expert Comment

by:hendridm
ID: 13710335
From my code, to reference each part:

Response.Write NameArray(1)   'Prints "Peter"
Response.Write NameArray(2)   'Prints "K"
Response.Write NameArray(3)   'Prints "Johnson"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 13710344
To clarify my above post, all you need is the following:

function howMany(strToQuery)
     dim intCaps
     intCaps = 0
     for i=1 to len(strToQuery)
          if Mid(strToQuery, i, 1) = UCase(Mid(strToQuery, i, 1)) then
               intCaps = intCaps + 1
          end if
     next
     howMany = intCaps
end function

the rest was just to show it working on a simple html page.

FtB
0
 
LVL 8

Assisted Solution

by:hendridm
hendridm earned 400 total points
ID: 13710427
Oh yeah, to get the count using my code:
Response.Write UBound(NameArray)

Fritz - your code doesn't actually return the parts of the string, no?
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 13710626
Oh darn! I didn't see that part of the question! I guess that I read it too quickly....

FtB
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 1600 total points
ID: 13710916
I suppose this is a quick way to break the string out:

function BreakIntoWords(strToQuery)
       strReturn = ""
     for i=1 to len(strToQuery)
          if Mid(strToQuery, i, 1) = UCase(Mid(strToQuery, i, 1)) then
                     strReturn = strReturn & " " & Mid(strToQuery, i, 1)
             else
                     strReturn = strReturn & Mid(strToQuery, i, 1)
          end if
     next
     BreakIntoWords = strReturn
end function
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question