我试图获取提供的html(span)之间的数据(在本例中为31)
这是原始代码(来自chrome中的inspect元素)
Run Code Online (Sandbox Code Playgroud)<span id="point_total" class="tooltip" oldtitle="Note: If the number is black, your points are actually a little bit negative. Don't worry, this just means you need to start subbing again." aria-describedby="ui-tooltip-0">31</span>
我有一个包含页面源的富文本框,这里是相同的代码,但在富文本框的第51行:
Run Code Online (Sandbox Code Playgroud)<DIV id=point_display>You have<BR><SPAN id=point_total class=tooltip jQuery16207621750175125325="23" oldtitle="Note: If the number is black, your points are actually a little bit negative. Don't worry, this just means you need to start subbing again.">17</SPAN><BR>Points </DIV><IMG style="FLOAT: right" title="Gain subscribers" border=0 alt="When people subscribe to you, you lose a point" src="http://static.subxcess.com/images/page/decoration/remove-1-point.png"> </DIV> …
我开始写一本C#书,我决定把RegEx放到混音中,让枯燥的控制台练习更有趣.我想要做的是在控制台中询问用户他们的电话号码,根据RegEx进行检查,然后捕获数字,这样我就可以按照我想要的方式对其进行格式化.除了RegEx捕获部分之外,我已经完成了所有工作.如何将捕获值转换为C#变量?
也可以随意更正任何代码格式或变量命名问题.
static void askPhoneNumber()
{
String pattern = @"[(]?(\d{3})[)]?[ -.]?(\d{3})[ -.]?(\d{4})";
System.Console.WriteLine("What is your phone number?");
String phoneNumber = Console.ReadLine();
while (!Regex.IsMatch(phoneNumber, pattern))
{
Console.WriteLine("Bad Input");
phoneNumber = Console.ReadLine();
}
Match match = Regex.Match(phoneNumber, pattern);
Capture capture = match.Groups.Captures;
System.Console.WriteLine(capture[1].Value + "-" + capture[2].Value + "-" + capture[3].Value);
}
Run Code Online (Sandbox Code Playgroud)