我在.txt文件中有这一行:
I just got home.\nDid you make lunch?\nOh, I see...
它只是一行,它的格式是这样的游戏,所以它就像这样,用\ n的。
我需要的是,当我打印它时,将它存储到变量或列表中后,将它打印在多行上,尊重\ n。像这样:
I just got home.\n
Did you make lunch?\n
Oh, I see...
在程序显示每个\ n之后,我想不出一种修改输出以创建新行的方法。我该怎么做?
答案 0 :(得分:1)
使用<Button x:Name="btnApp1" Width="56" Height="66" Margin="0,0,0,0" Style="{StaticResource AppButton}">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<iconPacks:PackIconMaterial Kind="StarOutline" Width="48" Height="48" VerticalAlignment="Top" HorizontalAlignment="Center"
Foreground="{TemplateBinding Foreground}" />
<TextBlock x:Name="tButton" HorizontalAlignment="Center" VerticalAlignment="Bottom"
Foreground="{TemplateBinding Foreground}" FontWeight="Bold">PVIE</TextBlock>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
功能就足够了:
str.replace()
输出:
s="I just got home.\nDid you make lunch?\nOh, I see..."
print(s.replace("\n", "\\n\n"))