Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

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
0
musclejack
Asked:
musclejack
  • 4
  • 3
2 Solutions
 
fritz_the_blankCommented:
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
 
hendridmCommented:
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
 
hendridmCommented:
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
Independent Software Vendors: 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!

 
fritz_the_blankCommented:
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
 
hendridmCommented:
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
 
fritz_the_blankCommented:
Oh darn! I didn't see that part of the question! I guess that I read it too quickly....

FtB
0
 
fritz_the_blankCommented:
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now