Hi, noob here.
Say I've got a paragraph of text saved in variable a,
and another paragraph of text (in a different language, it just so happens) saved in variable b.
How can I make a variable c which consists of...
[1st line of a]
[1st line of b]
[2nd line of a]
[2nd line of b]
[3rd line of a]
[3rd line of b], etc. etc. I think you get the idea.
It's for making dual-language .srt files.
Thanks!
splice two paragraphs of text into each other
Re: splice two paragraphs of text into each other
Are you saying that you have a script already that (erroneously) combines the lines of text like that, and you want to fix it? Or do you mean that you have an existing text file formatted like that, and you want to fix that existing file?
If you already have code, you should post what you have so far.
If you already have code, you should post what you have so far.
ste(phen|ve) kunkel
Re: splice two paragraphs of text into each other
Code: Select all
#Requires AutoHotkey v2.0
a := '
(
a
c
e
g
h
i
j
)'
b := '
(
b
d
f
)'
c := mix(a, b)
MsgBox c, 'Result', 'Iconi'
mix(a, b) {
a2 := StrSplit(a, '`n', '`r')
b2 := StrSplit(b, '`n', '`r')
out := ''
Loop Max(a2.Length, b2.Length) {
If A_Index <= a2.Length
out .= a2[A_Index] '`n'
If A_Index <= b2.Length
out .= b2[A_Index] '`n'
}
Return Trim(out, '`n')
}
Re: splice two paragraphs of text into each other
@kunkel321
I mean I have a paragraph of English text with a carriage return after roughly every 10 words or so,
and a paragraph of Chinese text which is a direct translation of the English text, cut similarly narrow,
and I want to combine the two paragraphs into one, double-length paragraph,
in which the first line is English, and the line directly below it is its translation,
and the same for the second line, third line, and every line. So...
[English line 1]
[Chinese line 1]
[English line 2]
[Chinese line 2]
--EDIT--
Actually it'd be a lot more convenient if I could just highlight both paragraphs at once, one after the other,
and have the second one be recognised as a different paragraph
simply by the fact it has a few empty carriage returns before it, rather than something on every line.
So it recognises what's the first paragraph, what's the second paragraph,
then just pastes the combined paragraph right over the top of the two highlighted paragraphs.
I mean I have a paragraph of English text with a carriage return after roughly every 10 words or so,
and a paragraph of Chinese text which is a direct translation of the English text, cut similarly narrow,
and I want to combine the two paragraphs into one, double-length paragraph,
in which the first line is English, and the line directly below it is its translation,
and the same for the second line, third line, and every line. So...
[English line 1]
[Chinese line 1]
[English line 2]
[Chinese line 2]
--EDIT--
Actually it'd be a lot more convenient if I could just highlight both paragraphs at once, one after the other,
and have the second one be recognised as a different paragraph
simply by the fact it has a few empty carriage returns before it, rather than something on every line.
So it recognises what's the first paragraph, what's the second paragraph,
then just pastes the combined paragraph right over the top of the two highlighted paragraphs.
Re: splice two paragraphs of text into each other
@mikeyww
Actually yeah Mikey you seem to have got it pretty much figured out there.
Thanks again!
Actually yeah Mikey you seem to have got it pretty much figured out there.
Thanks again!
Re: splice two paragraphs of text into each other
@mikeyww
Every block of strings should be divided by linefeed symbol.
Final trimming Trim(out, '`n') unneeded.
Every block of strings should be divided by linefeed symbol.
Final trimming Trim(out, '`n') unneeded.
SRT-format requirements
Please post your script code inside [code] ... [/code] block. Thank you.
Re: splice two paragraphs of text into each other
That is fine with me. Thank you. No specific example of the input or output was provided, so I made up my own. Blank lines are also not provided between the text pairs, but they can be added if needed.
Who is online
Users browsing this forum: Noitalommi_2 and 12 guests