-2

我想知道任何特定电视剧中使用的某些词的频率。如果我可以将 SRT 文件中的单词导出到 MS EXCEL,那将非常容易。谢谢

4

1 回答 1

0

要将 srt(读取文本文件)文件导出到 Excel,您可以使用以下内容:

Sub m_srt_2_excel(str_fullname_srt As String)
Dim fso_active As FileSystemObject
Dim text_active As TextStream
Dim str_text As String
Dim var_data As Variant
Dim lng_count As Long

    Set fso_active = New FileSystemObject
    Set text_active = fso_active.OpenTextFile(str_fullname_srt, ForReading)
    str_text = text_active.ReadAll
    var_data = Split(str_text, vbCrLf)
    lng_count = UBound(var_data)

    selection.Resize(lng_count + 1).Value = WorksheetFunction.Transpose(var_data)

    Set text_active = Nothing
    Set fso_active = Nothing

End Sub

或者您可以将 OpenTextFile 与函数结合起来计算出现次数:

Function f_count_string(str_text As String, str_find As String) As Long
Dim lng_len As Long

    lng_len = Len(str_text) - Len(Replace(str_text, str_find, vbNullString))
    f_count_string = lng_len / Len(str_find)
End Function
于 2015-03-23T01:03:49.920 回答