Sentence Extraction Topic is solved
Sentence Extraction
"Care should be taken not to make the above too lenient because if you ever inadvertently introduce an infinite loop of keystrokes (via a Send command that accidentally triggers other hotkeys) your computer could become unresponsive due to the rapid flood of keyboard events."
I have a sample post above. I want to put "`n" after every 62 words. The text above will be as follows. How can I do that?
"Care should be taken not to make the above too lenient because`n
if you ever inadvertently introduce an infinite loop of keyst`n
rokes (via a Send command that accidentally triggers other hot`n
keys) your computer could become unresponsive due to the rapid`n
flood of keyboard events"
I have a sample post above. I want to put "`n" after every 62 words. The text above will be as follows. How can I do that?
"Care should be taken not to make the above too lenient because`n
if you ever inadvertently introduce an infinite loop of keyst`n
rokes (via a Send command that accidentally triggers other hot`n
keys) your computer could become unresponsive due to the rapid`n
flood of keyboard events"
Re: Sentence Extraction
Use SubStr(), a loop, and a little math.
-
- Posts: 1472
- Joined: 05 May 2018, 12:23
Re: Sentence Extraction Topic is solved
you mean charactersvSky wrote: ↑07 Aug 2022, 23:44"Care should be taken not to make the above too lenient because if you ever inadvertently introduce an infinite loop of keystrokes (via a Send command that accidentally triggers other hotkeys) your computer could become unresponsive due to the rapid flood of keyboard events."
I have a sample post above. I want to put "`n" after every 62 words. The text above will be as follows. How can I do that?
"Care should be taken not to make the above too lenient because`n
if you ever inadvertently introduce an infinite loop of keyst`n
rokes (via a Send command that accidentally triggers other hot`n
keys) your computer could become unresponsive due to the rapid`n
flood of keyboard events"
a method based on boilers idea
Code: Select all
theText := "Care should be taken not to make the above too lenient because if you ever inadvertently introduce an infinite loop of keystrokes (via a Send command that accidentally triggers other hotkeys) your computer could become unresponsive due to the rapid flood of keyboard events."
newVar :=
startAt := 1
while(strlen(newVar) < strlen(theText))
{
newVar .= LTrim(substr(theText,startAt,62)," ") "`n"
startAt += 62
}
MsgBox, % newVar
exitapp
-
- Posts: 4398
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Sentence Extraction
Words or characters?
Code: Select all
text := "Care should be taken not to make the above too lenient because if you ever inadvertently introduce an infinite loop of keystrokes (via a Send command that accidentally triggers other hotkeys) your computer could become unresponsive due to the rapid flood of keyboard events."
MsgBox, % RegExReplace(text, "(^.{62}|.{61})\K ?", "`n")
Re: Sentence Extraction
If you don't want your words cut in the middle:
output =
Care should be taken not to make the above too lenient
because if you ever inadvertently introduce an infinite loop
of keystrokes (via a Send command that accidentally triggers
other hotkeys) your computer could become unresponsive due to
the rapid flood of keyboard events.
Code: Select all
#NoEnv
theText := "Care should be taken not to make the above too lenient because if you ever inadvertently introduce an infinite loop of keystrokes (via a Send command that accidentally triggers other hotkeys) your computer could become unresponsive due to the rapid flood of keyboard events."
maxLen := 62
Loop
{
if (StrLen(theText) >= maxLen) {
out .= (Line := SubStr(theText, 1, Instr(SubStr(theText, 1, maxLen), A_Space,, 0))) . "`n"
theText := StrReplace(theText, Line)
continue
}
out .= theText
break
}
MsgBox, 4096, output, % Clipboard := out
ExitApp
Care should be taken not to make the above too lenient
because if you ever inadvertently introduce an infinite loop
of keystrokes (via a Send command that accidentally triggers
other hotkeys) your computer could become unresponsive due to
the rapid flood of keyboard events.
Last edited by Xtra on 08 Aug 2022, 19:47, edited 1 time in total.
Re: Sentence Extraction
This is great but it cuts words. It needs to be flexible enough to only cut the line if there is space for the next character. @AHKStudent
Re: Sentence Extraction
@teadrinker yours also cuts words albeit less frequently.
-
- Posts: 4398
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Sentence Extraction
@Rikk03
There was no "do not cut words" condition, see the example from the first post.
There was no "do not cut words" condition, see the example from the first post.
Re: Sentence Extraction
Hi.
I have this function, but I don't remember where I got it from. Don't cut the words. The length is set on line 6. It can be put in a global variable, if it is necessary to change it interactively.
It may do the same as the Xtra script.
I have this function, but I don't remember where I got it from. Don't cut the words. The length is set on line 6. It can be put in a global variable, if it is necessary to change it interactively.
Code: Select all
PreviousClip:= "Care should be taken not to make the above too lenient because if you ever inadvertently introduce an infinite loop of keystrokes (via a Send command that accidentally triggers other hotkeys) your computer could become unresponsive due to the rapid flood of keyboard events."
CutTip:= st_wordWrap(PreviousClip)
MsgBox, %CutTip%
st_wordWrap(string, column=62, indentChar="")
{
indentLength := StrLen(indentChar)
Loop, Parse, string, `n, `r
{
If (StrLen(A_LoopField) > column)
{
pos := 1
Loop, Parse, A_LoopField, %A_Space%
If (pos + (loopLength := StrLen(A_LoopField)) <= column)
out .= (A_Index = 1 ? "" : " ") A_LoopField
, pos += loopLength + 1
Else
pos := loopLength + 1 + indentLength
, out .= "`n" indentChar A_LoopField
out .= "`n"
} Else
out .= A_LoopField "`n"
}
Return SubStr(out, 1, -1)
}
Re: Sentence Extraction
There is a situation like this; There is such a process in the code given as a solution. (LTrim(substr(theText,startAt...) I just found out that you can use "Subtr" with LTrim in this way. The AHK Documents don't give much information about how to use operations in different ways. I don't like asking questions, I just don't know how to do it.
Re: Sentence Extraction
Yes This solution really worked for me. Thank you.
That was another question I wanted to do. I will use this. Thanks
- flyingDman
- Posts: 2842
- Joined: 29 Sep 2013, 19:01
- flyingDman
- Posts: 2842
- Joined: 29 Sep 2013, 19:01
Re: Sentence Extraction
Or (not cutting words) :
(also trims each line of any final space)
Code: Select all
maxLen := 62
for x,y in strsplit(theText," ")
strlen(nT . y) < maxLen ? nT .= y " " : (nnT .= Rtrim(nT," ") "`n", nT := y " ")
msgbox % out := nnT . Rtrim(nT," ")
14.3 & 1.3.7
Re: Sentence Extraction
Haha that's what happens when zzzz. I will correct it.