我知道这个网站上有很多关于将多行正则表达式与 perl 匹配的问题,但是,我仍然无法弄清楚如何执行以下操作。因此,任何帮助或相关问题的链接将不胜感激。
我有一个input.txt由字段标签(由反斜杠标识)和字段内容构成的文本文件,如下所示:
\x text
\y text text
text text
\z text
Run Code Online (Sandbox Code Playgroud)
字段内容可以包含换行符,但为了进一步处理,我需要确保所有字段内容都在一行上。以下显然能够跨多行正确匹配,但是,它不会删除它,而是重新插入它。
#!/usr/bin/perl
$/ =undef;
{
open(my $in, "<", "input.txt") or die "impossible: $!";
open(my $out, ">", "output.txt") or die "Can't open output.txt: $!";
while (<$in>) {
s/\n([^\\])/ \1/g; # delete all line breaks unless followed by backslash and replace by a single space
print $out $_ ;
}
}
Run Code Online (Sandbox Code Playgroud)
它将空格添加到前面(所以我知道它正确地找到了它),但仍然保留了换行符。输出看起来像这样:
\x text
\y text text
text text
\z text
Run Code Online (Sandbox Code Playgroud)
而我希望得到这个:
\x text
\y …Run Code Online (Sandbox Code Playgroud) 我启动并运行了一个不和谐机器人。我的目标是在执行某个命令后向用户发送消息。这可行,但不知何故我的布局是错误的。我的字符串的第一行是正确的,之后其余的行将带有一些前导空格发送。
client = commands.Bot(command_prefix = '/')
@client.command()
async def start(ctx):
welcome_message = f"""
Welcome to my bot
here is a new line which has leading spaces
this line here has some aswell
"""
await ctx.send(welcome_message)
Run Code Online (Sandbox Code Playgroud)
所以基本上我的消息是这样的:
Welcome to my bot
here is a new line which has leading spaces
this line here has some aswell
Run Code Online (Sandbox Code Playgroud)
即使welcome_message = welcome_message.lstrip()在发送之前也不能解决问题。
Delphi 12 引入了多行字符串,我试图弄清楚它是如何工作的,来自 JavaScript 背景。在那里我可以直接在多行字符串中包含变量,例如:
const myName = 'Martin';
const myString = `Hi ${myName},
Say hello to
multi-line
strings!`;
Run Code Online (Sandbox Code Playgroud)
这将替换${myName}为变量的内容。在 Delphi 中如何使用新的'''多行字符串来实现这一点?
delphi string-interpolation multilinestring delphi-12-athens
在此shapefile中,几何列是线串,除了 4 个流到达 ( 8168547, 8171738, 8170616 ,8169920) 是多线串之外。
我需要将每个多线串仅转换为一个线串。我尝试了很多方法但没有成功。例如,我st_cast在 R 中尝试了 sf 包。但是,它增加了行数(它将每个多线串转换为多个线串)。
如何将每个多线串仅转换为一个线串?