我有一个这样的段落:
Rohit is a good boy.
He loves poetry.
He also sings.
我想颠倒这样的段落:
.boy good a is Rohit
.poetry loves He
.sings also He
我有来自this site的这个工作脚本。
Loop, Parse, clipboard, %A_Space%
new := RegExReplace(A_LoopField,"(.*)(\p{P})$","$2$1") A_Space new
Msgbox % Trim(new,A_Space)
但它一次只能反转一行。我无法为我的目的修改脚本。
答案 0 :(得分:0)
循环直线并创建一个包含当前行所有单词的数组,然后向后循环单词。如果一个单词以标点符号结尾,则将其放在单词的开头。
text =
(
Rohit is a good boy.
He loves poetry.
He also sings.
)
punctuationCharArray := [".",",","-",":",";","!","?"]
reversedText := ""
Loop, parse, text, `n, `r
{
line := A_LoopField
wordArray := StrSplit(line, " ")
i := wordArray.MaxIndex()
While (i>0) {
rawWord := wordArray[i]
punctuationChar := ""
Loop % punctuationCharArray.MaxIndex() { ;check if the last character of the word is one of the specified punctuation chars
If (SubStr(rawWord, -0) = punctuationCharArray[A_Index]) {
punctuationChar := punctuationCharArray[A_Index]
Break
}
}
word := (punctuationChar ? SubStr(rawWord, 1, -1) : rawWord) ;if there is a punctuation char in the end, omit that
reversedText .= punctuationChar . word . " " ;add the current (punctuation char), word and a space to the output text variable.
i--
}
reversedText .= "`r`n" ;add a new line
}
MsgBox % reversedText
输出:
。我很高兴是罗希特 诗歌爱他 .sings也是他
下一步也是反向括号。