Search code examples
naturallyspeaking

How can I trim all forms of white space (tabs, new lines, …) from a string in Dragon NaturallySpeaking's advanced scripting?


How can I trim all forms of white space (tabs, new lines, …) from a string in Dragon NaturallySpeaking's advanced scripting?

Trim() only removes white spaces. For example, the following voice command will type [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

Solution

  • Based on the work I did here:

    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

    One can adapt and create the following:

    ' 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
    

    Naturally, you can reference your myTrim function in a common Uses comment file, so you only have to write it once.

    Hth,