Vbscript 读取Word中使用的回车数量

Vbscript 读取Word中使用的回车数量,vbscript,ms-word,Vbscript,Ms Word,我通过计算track review启用后所做更改的总数来计算word文档的准确性。标点符号的错误使用按1/4分计算,而上下文或语法错误则扣满分1分 现在所有回车都被计算为满分。我想这要么被完全删除,要么可以通过它作为1/4扣减。我用下面的数数;并且,作为1/4的分数扣减 For Each myRevision In ActiveDocument.Revisions myRevision.Range.Select If myRevision.Type = wdRevisionInsert

我通过计算track review启用后所做更改的总数来计算word文档的准确性。标点符号的错误使用按1/4分计算,而上下文或语法错误则扣满分1分

现在所有回车都被计算为满分。我想这要么被完全删除,要么可以通过它作为1/4扣减。我用下面的数数;并且,作为1/4的分数扣减

For Each myRevision In ActiveDocument.Revisions
myRevision.Range.Select
    If myRevision.Type = wdRevisionInsert Then
        lngRevisions = Len(Selection.Text)
        For i = 1 To lngRevisions
            If Mid(Selection.Text, i, 1) = "," Then
                punct = punct + 1
            Else
            End If

            If Mid(Selection.Text, i, 1) = "." Then
                punct = punct + 1
            Else
            End If

            If Mid(Selection.Text, i, 1) = ";" Then
                punct = punct + 1
            Else
            End If
            If Mid(Selection.Text, i, 1) = "" Then
                punct = punct + 1
            Else
            End If
       Next i
       Count = Count + 1
    Else
    End If
Next

tCorrections = Count + punct * 0.25 - punct


Accuracy = ((tWords - tCorrections) / tWords) * 100
Accuracy = Round(Accuracy, 1)

通过类型到计数槽的映射(aMap),使用类型名称数组(阿拉贝尔)和数据中出现的类型字符串(sC),以灵活的方式对字符串进行分类。如本演示中所示:

Option Explicit

Dim aLabels : aLabels = Split("Vowels Consants Digits Punctuations EOLs Unclassified")
ReDim aCounts(UBound(aLabels))
Dim sC : sC = "abce1,2." & vbCr
Dim aMap : aMap = Array(0, 1, 1, 0, 2, 3, 2, 3, 4)
Dim sD : sD = sC & "d" & sC & "bb111."
Dim p, i
For p = 1 To Len(sD)
    i = Instr(sC, Mid(sD, p, 1))
    If 0 = i Then
       i = UBound(aLabels)
    Else
       i = aMap(i - 1)
    End If
    aCounts(i) = aCounts(i) + 1
Next
For i = 0 To UBound(aLabels)
    WScript.Echo Right("   " & aCounts(i), 3), aLabels(i)
Next
输出:

cscript 42505210.vbs
  4 Vowels
  6 Consants
  7 Digits
  5 Punctuations
  2 EOLs
  1 Unclassified
根据这些原始数据(类型频率),您可以添加特殊重量

更新wrt注释:

正如我所说:在计算原始频率后添加权重:

... as above ...
Dim nSum
' Std - all weights = 1
nSum = 0 : For Each i In aCounts : nSum = nSum + i : Next
WScript.Echo "all pigs are equal:", nSum
' No EOLs
nSum = 0 : For Each i In aCounts : nSum = nSum + i : Next : nSum = nSum - aCounts(4)
WScript.Echo "EOLs don't count:", nSum
nSum = 0 : aCounts(0) = aCounts(0) * 4 : For Each i In aCounts : nSum = nSum + i : Next
WScript.Echo "vowels count * 4:", nSum
其他输出:

all pigs are equal: 25
EOLs don't count: 23
vowels count * 4: 37

对不起,这让我很困惑。那么,我该如何设置要包含在1/4容量中的字符,或者完全不计算字符。我会将回车定义为字符吗?@kaswardy-您处理回车的方式与我在(第一版)演示中所做的完全相同:将concat vbCr放入类型字符串中,并将相应的组索引(4)放入映射中。