Wil*_*amK -1 vbscript asp-classic
我需要一个函数来使用经典的 asp 来检查字符串是否全部(或大部分)大写。(我需要防止用户使用全部大写输入标题。)
例如,如果一个由 30 个字母组成的字符串包含 20 个或更多大写字母,我需要将其标记为“全部大写”。所以《基督山伯爵》可以,但《基督山伯爵》不行。
我正在考虑从匹配的字母开始[^A-Z],但我该怎么做呢?
这需要使用经典 ASP 而不是 VB。
与 UCase(input) 进行比较,使其成为全有或全无检查;我更愿意看看 UCase 比率:
Option Explicit
Function Ucasity(s)
If Len(s) Then
Dim r : Set r = New RegExp
r.Global = True
r.Pattern = "[A-Z]"
Dim m : Set m = r.Execute(s)
Ucasity = m.Count / Len(s)
Else
Ucasity = 0
End If
End Function
Function qq(s) : qq = """" & s & """" : End Function
Dim s
For Each s In Array( _
"UPPERCASE but not ALL OR NOTHING" _
, "UPPERCASE" _
, "pipapo" _
, "UPPERCASEuppercase" _
, "" _
)
WScript.Echo qq(s), CStr(s = UCase(s)), UCasity(s)
Next
Run Code Online (Sandbox Code Playgroud)
输出:
Option Explicit
Function Ucasity(s)
If Len(s) Then
Dim r : Set r = New RegExp
r.Global = True
r.Pattern = "[A-Z]"
Dim m : Set m = r.Execute(s)
Ucasity = m.Count / Len(s)
Else
Ucasity = 0
End If
End Function
Function qq(s) : qq = """" & s & """" : End Function
Dim s
For Each s In Array( _
"UPPERCASE but not ALL OR NOTHING" _
, "UPPERCASE" _
, "pipapo" _
, "UPPERCASEuppercase" _
, "" _
)
WScript.Echo qq(s), CStr(s = UCase(s)), UCasity(s)
Next
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1987 次 |
| 最近记录: |