Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在c#中格式化此字符串以在消息框中显示结果集?_C# - Fatal编程技术网

如何在c#中格式化此字符串以在消息框中显示结果集?

如何在c#中格式化此字符串以在消息框中显示结果集?,c#,C#,我有一个像下面这样的字符串作为响应。 我想格式化这个字符串,这样每个参数都会一个接一个地出现。 就像我得到这根绳子一样 string str1 = @"testmode=0<br>MessageReceived=Your order dispached and will be delived<br>Messagecount1 <br>could not access file: Error=Not enough credit send."; 试试像这样的东

我有一个像下面这样的字符串作为响应。 我想格式化这个字符串,这样每个参数都会一个接一个地出现。 就像我得到这根绳子一样

string  str1 = @"testmode=0<br>MessageReceived=Your order dispached and will be delived<br>Messagecount1
<br>could not access file: Error=Not enough credit send.";
试试像这样的东西

string formatted = str1.Replace("<br>",Environment.NewLine);
string formatted=str1.Replace(“
”,Environment.NewLine);

这只会用换行符替换

标记。

不是最好的标记,但是:

MessageBox.Show(string.Join(Environment.NewLine, str1.Split(new string[]{"<br>", ":"}, StringSplitOptions.None)));
MessageBox.Show(string.Join(Environment.NewLine,str1.Split(新字符串[]{“
”,“:”},StringSplitOptions.None));
试试看

MessageBox.Show(str1.Replace(@“
”,Environment.NewLine));
无法访问文件:

你怎么知道你必须在那里换行?

也许可以尝试使用Replace将br改为换行。将代码放在这行后面:

str1.Replace("<br>", "\n");
str1.替换(“
”,“\n”);
str1.Split(新字符串[]{“
”,“:”})
消息是否为
html
格式?如果它的
XHTML
,它应该是

API只返回我需要格式化的那种消息,而不是html标记there@Sayse,将生成一个字符串数组。。。我假设(强调假设)OP希望使用换行符对其进行格式化…@DavidColwell-Ah touché@Fuex,如果您使用split,您最好将格式添加回一个字符串,以便将其发送到messagebox最后一位使用冒号(替换为“:\n”)不确定为什么要使用messagebox。。。但代码看起来会work@DavidColwell,标题上写着消息框,你是如何得到最后一条通缉线的?@Fuex,这要看情况而定。你怎么知道应该有一条新线路?是否每个冒号(:)都标记一个新行?如何获得最后一个通缉行?很好。我假设给出的测试数据中有一个错误。
MessageBox.Show(str1.Replace(@"<br>", Environment.NewLine));
str1.Replace("<br>", "\n");