我有以下字符串.
我们都知道你永远不会有太多瑜伽裤!今天的赠品是我最喜欢的@aloyoga\ud83d\ude0d\ud83c\udf81\ud83d\udcaa\ud83c\udffc我老实以为所有参与#JenSelterChallenge的人感到骄傲..我已经被承诺的水平所压倒,进步和过去几周的积极性.看到你的照片和标题每天都会给我的脸上带来一丝笑容.谢谢你们让它取得如此成功,对于尚未加入的人来说,现在还为时已晚!恭喜WEEK 3\u2014的获奖者,我将在本周末为您提供所有内容!\ ud83d\ude03 \n @ Vicfitness_ \n @ Bodyroxxfit \n @ Krvstah \n @ Lvlelissa3 \n @ ThisIsNaila \n @ X_i_a_r_a_ \n @ Btrevellini \n @ Nicolesfitjourney_ \n #Seltering
我想用Environment.NewLine替换\n.所以,我尝试了以下内容:
caption = caption.Replace("\n", Environment.NewLine);
Run Code Online (Sandbox Code Playgroud)
不工作.没有任何改变.当我宣布它时,我在上一步尝试过,
caption = Regex.Match(response, pattern).Groups[1].Value.Replace("\n", Environment.NewLine);
Run Code Online (Sandbox Code Playgroud)
也没工作.
但是,当我手动尝试输入这样的字符串时:
string test = "We all know you can never have too many yoga pants!! Today's giveaway is with my fav @aloyoga \ud83d\ude0d \ud83c\udf81\ud83d\udcaa\ud83c\udffcI am honestly so proud of everyone who has been participating in the #JenSelterChallenge.. I have been overwhelmed by the level of commitment, progress, and positivity over the last couple of weeks. Seeing your photos and captions puts a huge smile on my face everyday. Thank you guys for making it such a success and for those who haven't joined yet, it's not too late! Congrats to the winners of WEEK 3\u2014 I will DM you all this weekend!! \ud83d\ude03 \n@Vicfitness_\n@Bodyroxxfit\n@Krvstah\n@Lvlelissa3\n@ThisIsNaila \n@X_i_a_r_a_\n@Btrevellini\n@Nicolesfitjourney_ \n#Seltering";
test.Replace("\n", Environment.NewLine);
Run Code Online (Sandbox Code Playgroud)
它工作正常.但是,当我对字符串进行硬编码以及正常运行时,我不确定有什么不同.这是完全相同的字符串,我已经通过调试自己检查了它.有什么我不知道的吗?
当你执行转换为单个字符的"\n"时0x0A.你真正想要的是两个字符"\"和"n"彼此相邻.
放在@替换字符串前面,它将停止转换\n为0x0A
caption = caption.Replace(@"\n", Environment.NewLine);
Run Code Online (Sandbox Code Playgroud)
你也可以通过逃避斜线来做到这一点
caption = caption.Replace("\\n", Environment.NewLine);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
57 次 |
| 最近记录: |