使用c#在字符串中插入一个字符串 [英] Insert a string inside string using c#

查看:1929
本文介绍了使用c#在字符串中插入一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似的字符串,



I am having an string like,

<root>
<name>
asdf
</name>
<age>
21
</age>
<city>
kjhgf
</city>
<root>





我需要在标签内添加一个字符串,例如,





I need to add a string inside the tags like,

<root>
<name "htmltag">
asdf
</name>
<age "html tag">
21
</age>
<city "html tag">
kjhgf
</city>
</root>

推荐答案

try
            {
                string _strline = "<ul>This is ul</ul><li>This is li</li><b>This is bold</b>";
                string append = "xmlns=" + "\" http://www.w3.org/1999/xhtml\"";
                string result = string.Empty;
                var arr = Regex.Matches(_strline, @"<[A-Za-z-']+>").Cast<Match>().Select(m => m.Value).ToArray();
                var openTags = arr.Distinct().ToArray();
                result = _strline;
                for (int i = 0; i < openTags.Length; i++)
                {
                    var temp = openTags[i].Replace(">", " " + append + " >");
                    result = result.Replace(openTags[i], temp);

                }
                Console.WriteLine(_strline);
                Console.WriteLine(result);
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                throw ex;
            }


所以你的需要应该引起你不知道的事情的问题...

你没有这样做,没有问任何问题,所以我问。



你知道XML-Schema和数据之间的区别吗?

您想要向架构添加属性还是仅更改属性数据?

您使用哪种技术来编写XML以及使用它们时遇到的问题?

...



你认为这是一个问题和答案论坛; - )
So your need should lead to questions about things you don't know...
You didn't do that, asked no questions, so I ask.

You know the difference between the XML-Schema and the data?
You want to add an attribute to the schema or just change an attributes data?
Which tech you use for read write the XML and what's the problem you have with using them?
...

you see it's a QUESTION and ANSWERS Forum ;-)


这篇关于使用c#在字符串中插入一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆