public function firstnoc(byval descstr as string) as dictionary(of string, integer)
dim fnocidx as integer = 0
dim l = len(descstr$)
dim cnum as integer = 0
dim fcnum as integer = 0
dim idx24 as integer = 0
for n = 1 to l
if asc(mid$(descstr$, n, 1)) < 0 then
fnocidx = 0
if n + cnum >= 24 and n + cnum < 26 then
idx24 = n
end if
cnum += 1
else
if fnocidx = 0 then
fnocidx = n
fcnum = cnum
end if
end if
next n
dim dic as new dictionary(of string, integer)
if idx24 > 0 then
idx24 -= 1
end if
if fnocidx > 0 then
fnocidx -= 1
end if
dic.add("fulllen", l + cnum)
dic.add("fnocidx", fnocidx)
dic.add("cnum", cnum)
dic.add("fcnum", fcnum)
dic.add("idx24", idx24)
firstnoc = dic
end function
public function getmatdesc(byval matdesc as string)
matdesc = matdesc.replace(" ", " ")
'漢字後面第乙個字元fnocidx,前面有多少漢字fcnum,轉碼後長度fulllen,漢字數量cnum,
dim dic as dictionary(of string, integer) = firstnoc(matdesc)
'漢字後面第乙個字元fnocidx
dim fnocidx as integer = dic("fnocidx")
'轉碼後總長度fulllen
dim fulllen as integer = dic("fulllen")
'漢字數量cnum
dim cnum as integer = dic("cnum")
'漢字後面第乙個字元前漢字數量fcnum
dim fcnum as integer = dic("fcnum")
'前20個字元中的漢字數
dim idx24 as integer = dic("idx24")
'總長度lenmatdesc
dim lenmatdesc as integer = matdesc.length
'漢字後面第乙個字元前總長度lenmatdesc
dim fclen as integer = fcnum + fnocidx
'---------------------------------------
if fulllen = lenmatdesc then
'新增空格隔斷
dim fspace = matdesc.split(" ")(0).length
dim sspace as integer = 0
if matdesc.split(" ").count > 1 then
sspace = matdesc.split(" ")(1).length
end if
if fspace < 24 then
if fspace + sspace < 24 then
matdesc = left(matdesc, fspace + sspace + 1) & "
" & right(matdesc, lenmatdesc - (fspace + sspace + 1))
else
matdesc = left(matdesc, fspace) & "
" & right(matdesc, lenmatdesc - fspace)
end if
else
matdesc = left(matdesc, 24) & "
" & right(matdesc, lenmatdesc - 24)
end if
else
'含有漢字
if fulllen / 2 <> lenmatdesc then
'含有字元
if fnocidx < 24 then
if fnocidx > 0 then
'新增空格隔斷
dim fspace = matdesc.split(" ")(0).length
dim sspace as integer = 0
if matdesc.split(" ").count > 1 then
sspace = matdesc.split(" ")(1).length
end if
if fspace > fnocidx then
if idx24 <> 0 then
if fspace < idx24 then
if fspace + sspace < idx24 then
matdesc = left(matdesc, fspace + sspace) & "
" & right(matdesc, lenmatdesc - (fspace + sspace))
else
if fspace > idx24 then
matdesc = left(matdesc, fnocidx) & "
" & right(matdesc, lenmatdesc - fnocidx)
else
matdesc = left(matdesc, fspace) & "
" & right(matdesc, lenmatdesc - fspace)
end if
end if
else
matdesc = left(matdesc, idx24) & "
" & right(matdesc, lenmatdesc - idx24)
end if
else
matdesc = left(matdesc, fspace) & "
" & right(matdesc, lenmatdesc - fspace)
end if
else
if fspace + sspace < idx24 then
matdesc = left(matdesc, fspace + sspace) & "
" & right(matdesc, lenmatdesc - (fspace + sspace))
else
matdesc = left(matdesc, fspace) & "
" & right(matdesc, lenmatdesc - fspace)
end if
end if
else
if idx24 <> 0 then matdesc = left(matdesc, idx24) & "
" & right(matdesc, lenmatdesc - idx24)
end if
else
if idx24 <> 0 then matdesc = left(matdesc, idx24) & "
" & right(matdesc, lenmatdesc - idx24)
end if
else
'全部漢字
matdesc = left(matdesc, 12) & "
" & right(matdesc, lenmatdesc - 12)
end if
end if
return matdesc
end function
VB輸入字元的控制判斷,很短
在keypress裡面加入 if keyascii 48or keyascii 57 and keyascii 88or keyascii 65 and keyascii 97or keyascii 120 andkeyascii 8 andkeyascii asc andkeyascii asc ...
判斷字串是否含有中英文和數字
對於正規表示式一直不是很擅長,所以有必要記錄一下。行定位符是用來描述字串的邊界。表示行結尾 表示行開始如 de 表示以de開頭的字串 de 表示以de結尾的字串。我們在查詢的乙個單詞的時候,如an是否在乙個字串 gril and body 中存在,很明顯如果匹配的話,an肯定是可以匹配字串 gril...
VB判斷整除並整除
private sub command1 click dim m as integer,n as integer,d as integer dim s as long 儲存結果 m val text1.text n val text2.text d val text3.text s 0 sum m,...