1

这是我的文本文件的一部分:

[Script Info]
Title: Default Aegisub file
ScriptType: v4.00+
WrapStyle: 0
ScaledBorderAndShadow: yes
Collisions: Normal
Scroll Position: 0
Active Line: 0
Video Zoom Percent: 1
YCbCr Matrix: None

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR,MarginV, Encoding
Style: Default,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:0:03.84,0:0:07.17,Default,,0,0,0,,An Aztec temple.
Dialogue: 0,0:0:08.88,0:0:10.97,Default,,0,0,0,,Aztecs this far south?
Dialogue: 0,0:0:11.1,0:0:13.84,Default,,0,0,0,,Dr. Covas, we must stop.
This is sacred ground.
Dialogue: 0,0:0:13.88,0:0:15.85,Default,,0,0,0,,This could be the biggest
archeological discovery
Dialogue: 0,0:0:15.88,0:0:16.87,Default,,0,0,0,,of the 21st century.

我需要这样做(我跳过了一些部分来向您展示更改后的结果)

Dialogue: 0,0:0:03.84,0:0:07.17,Default,,0,0,0,,An Aztec temple.
Dialogue: 0,0:0:08.88,0:0:10.97,Default,,0,0,0,,Aztecs this far south?
Dialogue: 0,0:0:11.1,0:0:13.84,Default,,0,0,0,,Dr. Covas, we must stop.\NThis is sacred ground.
Dialogue: 0,0:0:13.88,0:0:15.85,Default,,0,0,0,,This could be the biggest\Narcheological discovery
Dialogue: 0,0:0:15.88,0:0:16.87,Default,,0,0,0,,of the 21st century.

我尝试了很多东西,例如:LoadedFile = Regex.Replace(LoadedFile, @"(?<=Dialogue.+)[\n\r]+^(Dialogue)", "\\N");

换句话说,只有当新行之后的文本不是“对话”时,我才想用\N替换新行

4

1 回答 1

1
string LoadedFile = File.ReadAllText("1.txt");
string result = Regex.Replace(LoadedFile, "(Dialogue.+?)\r\n^((?!Dialogue).*)$", "$1\\N$2", RegexOptions.Multiline);
于 2012-12-23T19:16:49.413 回答