![]() |
KnowBrainer Speech Recognition | ![]() |
Topic Title: Dragon command that will prepend hyphen in front of every line of selected text Topic Summary: Created On: 02/20/2021 01:28 PM Status: Post and Reply |
|
![]() |
|
Frequently, I need to turn the several lines of text into a bulleted list. For example, I will want to turn this:
list item 1 list item 2 list item 3
Into this:
- list item 1 - list item 2 - list item 3
I created a command that will send the keys "-{down}{Home}" X amount of times, which is not ideal because it requires me to know how many items I am listing. For example, I would have to say, "bullet list down 3" in order to prepend the - character 3 times. If it's a lot of text, then I need to run the command multiple times or sit there counting lines. I have better things to count!
so what I want is a command that will:
- read the currently selected text - count the amount of linebreaks in that text - insert a "-" character after every line break (i.e., at the beginning of every)
I have no idea how to go about this. Is this possible? ------------------------- Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017. |
|
|
|
![]() |
|
I think it's possible, although the implementation might be different than what you describe. What application or applications does this need to work in?
If Word, are "soft" hyphens OK? I'm referring to hyphens that are symbols that look like hyphens, but can't be acted on directly. Similar to bullet points in Word. |
|
|
|
![]() |
|
It needs to work outside of Dragon friendly apps; simple text editors without any Select-and-Say functionality. ------------------------- Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017. |
|
|
|
![]() |
|
This sort-of works in Notepad. But you have to be careful about where the selection starts and ends. It's not bulletproof, but it was a fun 20 minute project for a Saturday night!
No doubt a more experienced script-writer will come up with a better, more elegant solution. Sub Main Dim x As String SendKeys "^c", True Wait .5 Let x = Clipboard Wait .5 Let x = Replace(x, Chr$(10), "- ") SendDragonKeys x End Sub |
|
|
|
![]() |
|
This version is less fussy about where the selection starts.
Sub Main ' Prepend "- " to each line in a selection ' x is the selection ' y is an individual character within x ' z is a reconstructed version of x, with a hyphen starting each line Dim x, y, z As String Dim Lengthx, Count As Integer SendKeys "^c", True Wait 0.3 Let x = Clipboard Let Lengthx = Len(x) Let Count = 1 Let z = "- " ' Assume first character needs to be a hyphen While Count <= Lengthx Let y = Mid(x, Count, 1) If y = Chr$(10) Then Let y = "- " End If z = z & y Count = Count + 1 Wend Clipboard z SendKeys "^v", True End Sub |
|
|
|
![]() |
|
Finally, a hybrid between the two, which I think is the best so far.
Sub Main ' Prepend "- " to each line in a selection ' x is the selection Dim x As String SendKeys "^c", True Wait .3 Let x = Clipboard Wait .3 Let x = "- " & Replace(x, Chr$(10), "- ") Clipboard x SendKeys "^v", True End Sub |
|
|
|
![]() |
|
Thank you, this last one works great in my desired application.
I don't totally understand the code. "Dim x as string" -- what else would it be aside from a string? What does the dim function do exactly? I looked it up, but somebody probably needs to explain to me like I'm five. ------------------------- Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017. |
|
|
|
![]() |
|
The "Dim" statement means that "x" is a string and not something else that looks like a string, like a number. (The number "123" could be a string or an integer. If it's an integer, I can add another number to it. But if it's a string, I can't use it for math.)
Sometimes "Dim" statements are optional. They can be omitted and everything works fine. It's considered good form to include them. |
|
|
|
![]() |
|
Thanks Alan. I've extended your command to do the same thing but with different Markdown formatting elements. I think anybody who uses markdown frequently would benefit from the full command, so I'll post what I have here.
|
|
|
|
![]() |
|
I've been using this command to prepend elements to the beginning of every line in a selection to great effect, thank you.
Now I have the need to do the same thing but for appending elements to the end of the line.
I tried tweaking it to make this happen, but I realize I don't understand why this function works in the first place. Specifically, this part:
Let x = "- " & Replace(x, Chr$(10), "- ")
I must not understand the "Replace" function properly, even after reading the documentation.
If Chr$(10) is a linefeed, then it seems like this "Replace" function should replace all instances of linefeed with "- ", but that's not how it's actually behaving. Instead, it's like it's appending "- " after every linefeed, leaving the linefeeds in the text (instead of removing/replacing them).
So I guess, 2 questions:
1. Why doesn't the "replace" function remove all of the linefeeds?
2. How can I adapt this function to append the element to the end of every line instead of putting it at the beginning?
------------------------- Dragon Professional Individual v15.6. Windows 10. Knowbrainer 2017. |
|
|
FuseTalk Standard Edition v4.0 - © 1999-2022 FuseTalk™ Inc. All rights reserved.