gpt4 book ai didi

c# - 如何用双引号替换文件中的字符串

转载 作者:太空宇宙 更新时间:2023-11-03 21:10:14 26 4
gpt4 key购买 nike

想用 XYZ 替换我的文件中的文本 strText @Insurer输出像这样“XYZ”

直到现在我才这样做

strText.Replace("@Insurer",XYZ)

这给了我 XYZ 但不是这个“XYZ”

所以我做了这个

strText.Replace("\"@Insurer\"",XYZ)

但它没有用 XYZ 替换我的字符串

最佳答案

如果您希望引用替换之后的文本,那么您应该将替换字符串放在引号中:

strText.Replace("@Insurer", "\"" + XYZ + "\"")

否则,您将搜索文字字符串 "@Insurer" 并将其替换为 XYZ。因此,如果有引号(可能不是这种情况,否则您不会想要添加它们),那么这实际上会删除它们。

关于c# - 如何用双引号替换文件中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38179442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com