1
我正在嘗試做一些字符串操作,我需要採取多行字符串,並創建一個List<String>
分開\r\n
,以便我最終列出在字符串中找到的行。C#正則表達式強制結果不能轉義字符
但是,這樣做的Regex.Split我結束了與具有每一個
"
逃脫了\
行之後。
例如,輸入字符串的一個片段是:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<g2s:g2sMessage xmlns:g2s="http://www.gamingstandards.com/g2s/schemas/v1.0.3">
<g2s:g2sBody g2s:dateTimeSent="2012-11-06T09:12:38.006-08:00" g2s:egmId="RBG_1234"
g2s:hostId="1">
<g2s:communications g2s:commandId="37102" g2s:dateTime="2012-11-06T09:12:38.004-08:00"
g2s:deviceId="1"
g2s:errorCode="G2S_none"
當i執行以下使用拆分此字符串成List<String>
:
List<string> lines = new List<string>(Regex.Split(message, "\r\n"));
結果是:
<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<g2s:g2sMessage xmlns:g2s=\"http://www.gamingstandards.com/g2s/schemas/v1.0.3\">
<g2s:g2sBody g2s:dateTimeSent=\"2012-11-06T09:12:38.006-08:00\" g2s:egmId=\"RBG_1234\"
g2s:hostId=\"1\">
<g2s:communications g2s:commandId=\"37102\" g2s:dateTime=\"2012-11-06T09:12:38.004-08:00\"
g2s:deviceId=\"1\"
g2s:errorCode=\"G2S_none\"
我該如何做到這一點,而不會結束字符串塔沒有"
逃脫?
C#真的是逃避字符,還是隻是調試器顯示字符串的方式?
非常感謝。 – Chimera