Link to home
Start Free TrialLog in
Avatar of musclejack
musclejack

asked on

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

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
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

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>
Avatar of hendridm
hendridm

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>
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"
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
SOLUTION
Avatar of hendridm
hendridm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh darn! I didn't see that part of the question! I guess that I read it too quickly....

FtB
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial