簡體   English   中英

如何在 c# 中轉義字符串中的字符

[英]How to escape characters in string in c#

我有這個字符串,並得到一個錯誤

字符串文本 =

<root><Info id="inseID">17</Info><note><123comments></note></root>

我想把它轉換成

<root><Info id="inseID">17</Info><note>&lt;123comments&gt;</note></root>

使用 linq 到 xml。

var text = "<root><Info id=\"inseID\">17</Info><note></note></root>";
var xml = XElement.Parse(text);
xml.Element("note").Add("<123comments>");
//string result = xml.ToString(); // will be escaped

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM