字符串解析的有关问题
字符串解析的问题,
<asp:Button id="Button1" runat="server" Text="Button" Height="30"></asp:Button>
类似这类字符,怎么解析能得到其中的属性值。
例如:Text的值Button
希望高手给出高效的解决方法
------解决方案--------------------
正则表达式
------解决方案--------------------
当作xml,用xpaths找可以吗
------解决方案--------------------
解析xml吗。
------解决方案--------------------
寻找字符串吧.不过这种办法也只是个馊主意
------解决方案--------------------
用xml吧,都是满足xml定义的
------解决方案--------------------
http://topic.****.net/u/20081024/00/200484df-bf81-4449-8c63-2ba0cac07a56.html 不知道这个会不会对你有帮助
------解决方案--------------------
ex:
<asp:Button id="Button1" runat="server" Text="Button" Height="30"></asp:Button>
类似这类字符,怎么解析能得到其中的属性值。
例如:Text的值Button
希望高手给出高效的解决方法
------解决方案--------------------
正则表达式
------解决方案--------------------
当作xml,用xpaths找可以吗
------解决方案--------------------
解析xml吗。
------解决方案--------------------
寻找字符串吧.不过这种办法也只是个馊主意
------解决方案--------------------
用xml吧,都是满足xml定义的
------解决方案--------------------
http://topic.****.net/u/20081024/00/200484df-bf81-4449-8c63-2ba0cac07a56.html 不知道这个会不会对你有帮助
------解决方案--------------------
ex:
- C# code
System.Xml.XmlDocument doc = new XmlDocument(); doc.Load(@"xml文件路径"); XmlNodeList nodes = doc.DocumentElement.ChildNodes; double count = 0; for (int i = 0; i < nodes.Count; i++) { if (nodes[i].Name == "ShuJu") { double temp; temp = Convert.ToDouble(nodes[i].Attributes["TongHuaSC"].Value); count += temp; } } this.textBox1.Text = count.ToString();
------解决方案--------------------
System.Xml.XmlDocument doc = new XmlDocument();
doc.Load(@"xml文件路径");
XmlNodeList nodes = doc.DocumentElement.ChildNodes;
double count = 0;
for (int i = 0; i < nodes.Count; i++)
{
if (nodes[i].Name == "ShuJu")
{
double temp;
temp = Convert.ToDouble(nodes[i].Attributes["TongHuaSC"].Value);
count += temp;
}
}
this.textBox1.Text = count.ToString();
------解决方案--------------------
很多方法的,正则,XML解析,还可以用js
------解决方案--------------------
js就可以搞定.
------解决方案--------------------
方法很多,一般用正则
------解决方案--------------------
- C# code
(?<=")\w+(?=")
------解决方案--------------------
正则,XML解析都可以
------解决方案--------------------
同上
------解决方案--------------------
如果你是想匹配 Text="..." 中...的内容,则下面就是你所要的:
string t = Regex.Match(s, @"(?i)\btext\s*=\s*""([^""]*)""").Groups[1].Value;
- C# code
using System; using System.Text.RegularExpressions; class Program { static void Main() { string s = "<asp:Button id=\"Button1\" runat=\"server\" Text=\"Button\" Height=\"30\"> </asp:Button>"; string t = Regex.Match(s, @"(?i)\btext\s*=\s*""([^""]*)""").Groups[1].Value; Console.WriteLine(t); // 输出:Button } }