Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xojo计算HTML中的单词-删除标记&;其他不需要的内容可能会影响计数?_Html_Xojo - Fatal编程技术网

Xojo计算HTML中的单词-删除标记&;其他不需要的内容可能会影响计数?

Xojo计算HTML中的单词-删除标记&;其他不需要的内容可能会影响计数?,html,xojo,Html,Xojo,我在计时器的action事件中插入了一些临时变量,当您键入标记时,它会将标记转换为html。此事件将html放置在变量mHTML中 -Code Above Here- Dim re As New RegEx re.SearchPattern = "<[^<>]+>" re.ReplacementPattern = "" re.Options.ReplaceAllMatches = True Dim html As String = mHTML Dim plain As

我在计时器的action事件中插入了一些临时变量,当您键入标记时,它会将标记转换为html。此事件将html放置在变量mHTML中

-Code Above Here-

Dim re As New RegEx
re.SearchPattern = "<[^<>]+>"
re.ReplacementPattern = ""
re.Options.ReplaceAllMatches = True

Dim html As String = mHTML
Dim plain As String = re.Replace(html)

re.SearchPattern = "\n+"
re.ReplacementPattern = " "
re.Options.ReplaceAllMatches = True

plain = re.Replace(plain)

re.SearchPattern = "\s+"
re.ReplacementPattern = " "
re.Options.ReplaceAllMatches = True

plain = re.Replace(plain)
plain = trim(plain)

Dim MCount as Integer = CountFields(plain, " ")
Dim C as New Clipboard
C.Text = plain

Label.Text = Str(MCount + 1)

-More Code Below Here-
我想数一数文本中的单词,并将它们显示在标签中。我将单词定义为一个或多个不包含html标记的可打印字符

这段代码首先从变量mHTML获取html。然后我使用Regex删除所有标记。然后,我使用正则表达式将一个或多个行的末尾替换为一个空格。然后我使用正则表达式将一个或多个空格替换为单个空格。然后从字符串的开头或结尾修剪任何空格。然后,我计算字符串中的空格数并加1以获得单词计数,该计数显示在应用程序窗口的标签中

我还添加了一些代码来复制清理文本,在清理文本中,我计算了剪贴板上的空格,以检查代码的执行情况

有什么更有效的方法可以做到这一点。我添加的代码上下都有无法更改的代码。上面我添加的代码包括将HTML放入变量mHTML的代码

-Code Above Here-

Dim re As New RegEx
re.SearchPattern = "<[^<>]+>"
re.ReplacementPattern = ""
re.Options.ReplaceAllMatches = True

Dim html As String = mHTML
Dim plain As String = re.Replace(html)

re.SearchPattern = "\n+"
re.ReplacementPattern = " "
re.Options.ReplaceAllMatches = True

plain = re.Replace(plain)

re.SearchPattern = "\s+"
re.ReplacementPattern = " "
re.Options.ReplaceAllMatches = True

plain = re.Replace(plain)
plain = trim(plain)

Dim MCount as Integer = CountFields(plain, " ")
Dim C as New Clipboard
C.Text = plain

Label.Text = Str(MCount + 1)

-More Code Below Here-
-上面的代码-
Dim re作为新正则表达式
re.SearchPattern=“”
re.ReplacementPattern=“”
re.Options.ReplaceAllMatches=True
将html设置为字符串=mHTML
Dim plain As String=re.Replace(html)
re.SearchPattern=“\n+”
re.ReplacementPattern=“”
re.Options.ReplaceAllMatches=True
普通=重新更换(普通)
re.SearchPattern=“\s+”
re.ReplacementPattern=“”
re.Options.ReplaceAllMatches=True
普通=重新更换(普通)
普通=修剪(普通)
Dim MCount为整数=计数字段(普通“”)
将C设置为新剪贴板
C.文本=纯文本
Label.Text=Str(MCount+1)
-下面有更多代码-

我认为删除标记的过程是合理的,除非标记中的字符串中有“>”字符,但我不确定是否允许这样做

您是在macOS还是Linux系统上执行此操作

然后,您可以尝试使用cmdline工具
wc
通过向文本传递不带标记的文本来计算单词数。使用Shell类调用该工具,并通过stdin将文本传递给它,或者将文本保存到临时文件并将其路径传递给命令。但是,首先在终端中手动尝试
wc
命令,看看它是否给出了预期的结果