注册 登录
编程论坛 ASP技术论坛

ASP新手的问题关于Number and String Functions

afton 发布于 2010-06-10 08:31, 545 次点击
问题是这样的,编一个 script counts the number of letters (do not count spaces), the number of spaces and the number of “A”s (capital or small)
我现在就是the number of “A”s (capital or small)这一部分弄不出来,大家教教我呀!!

<%
Option Explicit
Dim intspaces, txtwholething, counter
'grab the string from the textbox
txtwholething = Request("thestuff")
'output the length of the string
if txtwholething <>"" then
    Response.write "You entered a string of " & Len(txtwholething) & " characters long<br>"
    'find out how many spaces are in the string
    'since we know how long the string is, use a For Next loop
    For counter = 1 to Len(txtwholething)
        'start going through the string one letter at a time
        'the counter value tells the MID( ) function which letter to get next
        If MID(txtwholething, counter, 1) = " " Then
            'keep track of the number of spaces found
            intspaces = intspaces + 1
        End If
    'if we are not at the end of the string, go back and get another character
    Next

    'When we are done output the number of spaces
    Response.write "There are " & intspaces & " space(s) in the string"
end if
%>

<HTML><HEAD><TITLE>Student Login Form</TITLE></HEAD>           
    <BODY BGCOLOR = "#CCFFCC">                    
        <FORM METHOD=POST>
            Enter a word or sentence:
            <INPUT TYPE=TEXT NAME="thestuff"><BR><BR>
            <INPUT TYPE=SUBMIT VALUE="Click to Enter">
        </FORM>
    </BODY>
</HTML>


4 回复
#2
gupiao1752010-06-10 14:44
你想实现一个把一个字母或一个句子转化为大写或小写的,并统计其字符个数的函数??是这样吗?
#3
afton2010-06-11 06:28
就是想我输入一个句子,统计出这个句子有多少个字(不包括空格),然后统计有多少空格,统计有几个字母A(包括大小写)。这3个功能。

现在就是有几个字母A(包括大小写)我没弄出来。
#4
hams2010-06-11 08:45
<%
Option Explicit
Dim intspaces, intspacesa, txtwholething, counter, sstring
'grab the string from the textbox
txtwholething = Request("thestuff")
'output the length of the string
if txtwholething <>"" then
    intspaces =0
    intspacesa =0
    Response.write "You entered a string of " & Len(txtwholething) & " characters long<br>"
    'find out how many spaces are in the string
    'since we know how long the string is, use a For Next loop
    For counter = 1 to Len(txtwholething)
        sstring=MID(txtwholething, counter, 1)
        If ASC(sstring)=32 Then intspaces = intspaces + 1
        If ASC(sstring)=65 or ASC(sstring)=97 Then intspacesa = intspacesa + 1
    Next

    'When we are done output the number of spaces
    Response.write "There are " & intspaces & " space(s) in the string"
    Response.write "There are " & intspacesa & " A in the string"

end if
%>

<HTML><HEAD><TITLE>Student Login Form</TITLE></HEAD>           
    <BODY BGCOLOR = "#CCFFCC">                    
        <FORM METHOD=POST>
            Enter a word or sentence:
            <INPUT TYPE=TEXT NAME="thestuff"><BR><BR>
            <INPUT TYPE=SUBMIT VALUE="Click to Enter">
        </FORM>
    </BODY>
</HTML>
#5
afton2010-06-11 11:31
谢谢啦,我还要好好地学习一下。
1