急!用VB編寫程式,對輸入的字串進行識別,找出其中大寫字母 小寫字母 空格 數字及其他字元的個數

時間 2021-07-01 02:07:54

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樓:匿名使用者

我怎麼覺得我前幾天回答了這個問題呀!

編寫程式,使輸入的字串倒序輸出

按你的思路for迴圈只是把第乙個字元放到最後了。應將前i 1個也進行這個操作,然後前i 2個 不理解可詳細諮詢我。用j a編寫一段程式,輸入一段字串,然後輸出該字串的倒序狀態。import 倒入的util中的包用scanner類 public class testohcefor int i 0 i ...

C語言編寫程式,判斷輸入的字串是否是回文

小夏在深圳 源 如下 include int main int n,reversedinteger 0,remainder,originalinteger printf 輸入乙個整數 scanf d n originalinteger n 翻轉 while n 0 remainder n 10 re...

用指標編寫程式,先從鍵盤上輸入字串,然後在該字串中查詢是否有 x 字元。如果有,輸出第一

include stdio.h void main int research char string return 1 執行過了,是正確的! 原始碼如下 include int searcha char s,int c int main int argc,const char argv index ...