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

# 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
• 4
• 3
2 Solutions

Commented:
Here you go:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<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>

</body>
</html>
0

Commented:
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

Commented:
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

Commented:
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

Commented:
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

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

FtB
0

Commented:
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

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