1樓:
遍歷字串,比較其ascii,分別用不同的變數
參考**
dim intnumber as integer, intucase as integer, intlcase as integer, intspace as integer
dim i as integer, strtmp as string
intnumber = 0
intucase = 0
intlcase = 0
intspace = 0
for i = 1 to len(text1.text)
strtmp = mid(text1.text, i, 1)
if asc(strtmp) > 47 and asc(strtmp) < 58 then intnumber = intnumber + 1
if asc(strtmp) > 64 and asc(strtmp) < 91 then intucase = intucase + 1 '大寫字母個數
if asc(strtmp) > 96 and asc(strtmp) < 123 then intlcase = intlcase + 1
if asc(strtmp) = 32 then intspace = intspace + 1
next
2樓:匿名使用者
option explicit
'在窗體中添一個commandbutton、一個textbox
private sub command1_click()
dim intl as long, intu as long, ints as long, intn as long, into as long
dim i as long, char as string * 1
for i = 1 to len(text1.text)
char = mid(text1.text, i, 1)
select case char
case "a" to "z": intu = intu + 1
case "a" to "z": intl = intl + 1
case "0" to "9": intn = intn + 1
case " ": ints = ints + 1
case else: into = into + 1
end select
next
msgbox "textbox中的字串統計結果:" & vbcrlf & space(2) & "大寫字母:" & intu & "個" _
& vbcrlf & space(2) & "小寫字母:" & intl & "個" _
& vbcrlf & space(2) & "數字:" & intn & "個" _
& vbcrlf & space(2) & "空格:" & ints & "個" _
& vbcrlf & space(2) & "其它字元:" & into & "個", vbokonly or vbinformation, "統計字元輸出"
end sub
3樓:匿名使用者
可以把字元遍歷一下,然後用ascii值來判斷統計,具體函式請參考msdn。
4樓:匿名使用者
我怎麼覺得我前幾天回答了這個問題呀!
編寫程式,輸入字串,輸出其中最長的字串。要求使用指標陣列實現
問明 include include int main int i 0 char s 80 max 80 printf 輸入五個字串 n scanf s s strcpy max,s for i 1 i 5 i scanf s s if strcmp max,s 0 strcpy max,s pri...
編寫程式,建立帶有節點的單向連結串列,輸入字串,並按從小到
int main link head 連結串列 不帶頭節點 int n printf 輸入連結串列的長度n scanf d n printf 連續輸入 d個資料 以空格隔開 n head createlink n printf n原本連結串列的節點是 displink head linksort h...
編寫程式,輸入以回車符結束的字串(少於字元),將該字串按逆序輸出
宣告一個大於或等於80長度的字元陣列,例如char a 100 使用gets 函式輸入字串,該字串以回車符作為結束標記。獲得字串的長度,以該長度值 1作為起點,以0作為終點,迴圈輸出字元。注意 獲得字串長度可以用庫的strlen 函式,該函式返回字串的實際長度,其中不包含空字元。測試 測試 incl...