在 Dragon Naturally Speaking 高级脚本中,如何从字符串中 trim 所有形式的白色 space(制表符、换行符……)?
How can I trim all forms of white space (tabs, new lines, …) from a string in Dragon NaturallySpeaking's advanced scripting?
如何在 Dragon NaturallySpeaking 的高级脚本中从字符串中 trim 所有形式的白色 space(制表符、换行符……)?
Trim()
仅删除白色 spaces。例如,以下语音命令将键入 [tab]test
' Tested with Dragon NaturallySpeaking 12.5 Professional on Windows 7 SP1 x64 Ultimate
Sub Main
s = vbTab & "test"
s = Trim(s)
SendKeys s
End Sub
我不知道 Trim 命令会自动删除制表符和其他空格,但您可以使用“替换”命令一个一个地删除空格。
Sub Main
s = vbTab & "test"
s = Trim(s)
s = Replace (s, Chr(9), "") ' Replaces the tab character written in ASCII code with nothing
s = Replace (s, Chr(10), "") ' Replaces the LF written in ASCII code with nothing
s = Replace (s, Chr(13), "") ' Replaces the CR written in ASCII code with nothing
SendKeys s
End Sub
这是一个部分解决方案:它将删除所有这些空格,即使是在字符串中。如果您想保留这些字符,则必须找到一种方法来测试第一个或最后一个字符是否为空白,并将它们替换为空字符。我没法很快想出那个,因为我以前没做过。
基于我在这里所做的工作:
CheckNewPara is here:
http://knowbrainer.com/forums/forum/messageview.cfm?catid=4&threadid=2739&discTab=true&messid=11427&parentid=11409&FTVAR_FORUMVIEWTMP=Single
Or search the forum for that term, and note, what it does is look back
to see what existing character(s) exist prior to where the cursor is
when you call the function to decide what to do next
可以改编并创建以下内容:
' Tested with Dragon NaturallySpeaking 13 Professional on Windows 8.1
Sub Main
s = vbTab & " " & vbTab & "test"
s = myTrim(s)
MsgBox """" & s & """"
End Sub
Function myTrim ( s As String )
While Left(s,1)=Chr(9) Or Left(s,1)=Chr(10) Or Left(s,1)=Chr(13) Or Left(s,1)=" "
s=Mid(s,2)
Wend
While Right(s,1)=Chr(9) Or Right(s,1)=Chr(10) Or Right(s,1)=Chr(13) Or Right(s,1)=" "
s=Mid(s,1,Len(s)-1)
Wend
myTrim = s
End Function
当然,你可以在普通的Uses注释文件中引用你的myTrim函数,所以你只需要写一次。
Hth,
如何在 Dragon NaturallySpeaking 的高级脚本中从字符串中 trim 所有形式的白色 space(制表符、换行符……)?
Trim()
仅删除白色 spaces。例如,以下语音命令将键入 [tab]test
' Tested with Dragon NaturallySpeaking 12.5 Professional on Windows 7 SP1 x64 Ultimate
Sub Main
s = vbTab & "test"
s = Trim(s)
SendKeys s
End Sub
我不知道 Trim 命令会自动删除制表符和其他空格,但您可以使用“替换”命令一个一个地删除空格。
Sub Main
s = vbTab & "test"
s = Trim(s)
s = Replace (s, Chr(9), "") ' Replaces the tab character written in ASCII code with nothing
s = Replace (s, Chr(10), "") ' Replaces the LF written in ASCII code with nothing
s = Replace (s, Chr(13), "") ' Replaces the CR written in ASCII code with nothing
SendKeys s
End Sub
这是一个部分解决方案:它将删除所有这些空格,即使是在字符串中。如果您想保留这些字符,则必须找到一种方法来测试第一个或最后一个字符是否为空白,并将它们替换为空字符。我没法很快想出那个,因为我以前没做过。
基于我在这里所做的工作:
CheckNewPara is here: http://knowbrainer.com/forums/forum/messageview.cfm?catid=4&threadid=2739&discTab=true&messid=11427&parentid=11409&FTVAR_FORUMVIEWTMP=Single Or search the forum for that term, and note, what it does is look back to see what existing character(s) exist prior to where the cursor is when you call the function to decide what to do next
可以改编并创建以下内容:
' Tested with Dragon NaturallySpeaking 13 Professional on Windows 8.1
Sub Main
s = vbTab & " " & vbTab & "test"
s = myTrim(s)
MsgBox """" & s & """"
End Sub
Function myTrim ( s As String )
While Left(s,1)=Chr(9) Or Left(s,1)=Chr(10) Or Left(s,1)=Chr(13) Or Left(s,1)=" "
s=Mid(s,2)
Wend
While Right(s,1)=Chr(9) Or Right(s,1)=Chr(10) Or Right(s,1)=Chr(13) Or Right(s,1)=" "
s=Mid(s,1,Len(s)-1)
Wend
myTrim = s
End Function
当然,你可以在普通的Uses注释文件中引用你的myTrim函数,所以你只需要写一次。
Hth,