小编Joh*_*ers的帖子

使用Regex解析HTML

我有Bing html,我想解析它的结果:

    string BingRegex = "<div class=\"sb_tlst\"><h3><a href=\"(.*?)\"";
    string[] results = Regex.Matches(responseStr, BingRegex).Cast<Match>().Select(m => m.Value).ToArray();
Run Code Online (Sandbox Code Playgroud)

我将结果发送到数组,但它将模式添加到每个结果,如:

<div class=\"sb_tlst\"><h3><a href=\"www.cnn.com\"
<div class=\"sb_tlst\"><h3><a href=\"www.google.com\"
<div class=\"sb_tlst\"><h3><a href=\"www.gmail.com\"
Run Code Online (Sandbox Code Playgroud)

知道我怎么能解决这个问题并获得网址?

c# regex wpf

-2
推荐指数
1
解决办法
429
查看次数

详细信息视图,数据列表,列表视图和表单视图之间的区别

我想更详细地了解

  • 数据清单
  • 详细信息视图,
  • 表单视图和
  • 列表显示。

以及何时应使用它们创建网站?

c# asp.net

-2
推荐指数
1
解决办法
7872
查看次数

System.NullReferenceException未被用户代码处理

int item = (int)Session["item"];我的代码中的这一行给了我一个,NullReferenceException 但我不理解

这是我的代码

它是一个自适应测验的代码,使用自适应算法,从数据库中检索包含重量(水平)和学生水平的问题的问题,因此根据学生水平,将挑选问题,并根据学生的答案,下一个问题将被张贴

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Collections;

using System.Data;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Configuration;


namespace WebApplication2
{


    partial class completeTest : System.Web.UI.Page
    {
        int level = 0;
        SqlDataSource QuizDataSource = new SqlDataSource();
        SqlCommand SqlCmd1;
        SqlConnection cn;
        SqlDataReader dr;
        System.Web.UI.WebControls.RadioButton rb1=new RadioButton();
        System.Web.UI.WebControls.RadioButton rb2 = new RadioButton();
        System.Web.UI.WebControls.RadioButton rb3 = new RadioButton();
        System.Web.UI.WebControls.RadioButton rb4 = new RadioButton();

        int weight;


        protected void Page_Load(object sender, System.EventArgs …
Run Code Online (Sandbox Code Playgroud)

c# sql-server nullreferenceexception

-2
推荐指数
1
解决办法
2837
查看次数

Foreach循环在同一个类的几个实例上

我正在尝试建立一个航空公司预订系统,因为这是我的同事考试项目,所以我想如果我这样做,我可以和他一样努力.我是一名PHP(是的,OO)程序员,正在转向C#.

我创建了一个类的几个版本,如下:

    Vluchten flight1 = new Vluchten("1337", "Scandinavian Airlines", "Oslo Intl", 180, 162);
    Vluchten flight2 = new Vluchten("101", "KLM", "Derpistan", 20, 17);
    Vluchten flight3 = new Vluchten("112", "Ryan Air", "Doetinchem Rock City", 10, 7);
Run Code Online (Sandbox Code Playgroud)

现在我想知道,我已经做好了这些,但有没有办法可以循环使用,这样我就可以把它们放在datagridview表中了?

c# foreach

-2
推荐指数
1
解决办法
233
查看次数

从字节数组中读取单字节的最佳方法

我有字节数组,我想逐个读取这些字节并将其转换为int.我在数组的字节中获取日期,因此需要从中创建DataTime对象.我正在使用以下代码.从绩效角度来看,最佳方法应该是什么?

byte[] date = {25, 10, 13, 04, 16, 26} //day month year hour minute second

CaptureTime = new DateTime(
                        (int)(new ArraySegment<byte>(date, 2, 1).ToArray()[0]), // Year
                        (int)(new ArraySegment<byte>(date, 1, 1).ToArray()[0]), // Month
                        (int)(new ArraySegment<byte>(date, 0, 1).ToArray()[0]), // Day
                        (int)(new ArraySegment<byte>(date, 3, 1).ToArray()[0]), //Hours
                        (int)(new ArraySegment<byte>(date, 4, 1).ToArray()[0]), //Minutes
                        (int)(new ArraySegment<byte>(date, 5, 1).ToArray()[0])); //Seconds
Run Code Online (Sandbox Code Playgroud)

上面的代码工作正常,但性能观点是那么好或有更好的方法来处理这个?

c# arrays byte

-2
推荐指数
1
解决办法
468
查看次数

ExecuteNonQuery 需要打开的可用连接。连接的当前状态已关闭

我想检查发票表中的发票号是否不存在,然后添加新发票号并在发票详细信息表中填写发票详细信息,否则如果发票表中存在发票号,我想更新“总计”字段,以防发票有更多班级中\的一项以上:

\n\n
StockClass stk = new StockClass();\n\nstk.Quantity = txtQuantity.Text;\nstk.StockID = txtStockID.Text;\nstk.QtyUpdate();\nMessageBox.Show("Stock record has been Successfully updated ");\n\nInvoiceClass invclass = new InvoiceClass();\n\ntry\n{\nOleDbConnection myConnection = default(OleDbConnection);\nmyConnection = new OleDbConnection(cs);\n\nOleDbCommand myCommand = default(OleDbCommand);\n\nmyCommand = new OleDbCommand("SELECT InvoiceNo FROM Invoices WHERE InvoiceNo = @InvoiceNo", myConnection);\nOleDbParameter invono = new OleDbParameter("@username", OleDbType.VarChar);\ninvono.Value = txtInvoiceNo.Text;\nmyCommand.Parameters.Add(invono);\n\n\nmyCommand.Connection.Open();\n\nOleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);\n\nif (myReader.Read() == true)\n{\ninvclass.InvoiceNo = txtInvoiceNo.Text;\ninvclass.Total = txtGrandTotal.Text;\ninvclass.Date = InvDate.Text;\n\ninvclass.updateinvoNumber();\n}\nelse\n{\ninvclass.InvoiceNo = txtInvoiceNo.Text;\ninvclass.Total = txtGrandTotal.Text;\ninvclass.Date = InvDate.Text;\n\ninvclass.AddNewinvoNumber();\n\ninvclass.InvoiceID = txtInvoiceNo.Text;\ninvclass.ProductID = txtProdID.Text;\ninvclass.ProName = txtProdName.Text;\ninvclass.ProType = txtProdType.Text;\ninvclass.ProSize = txtProdSize.Text;\ninvclass.Quantity = textQty.Text;\ninvclass.UnitPrice = txtPrice.Text;\ninvclass.Total …
Run Code Online (Sandbox Code Playgroud)

.net c# ado.net

-2
推荐指数
1
解决办法
659
查看次数

我可以通过代码解决验证码(获取图像和返回字符串的功能)

我通过我的代码向我的Gmail帐户发送了许多消息,有时我得到一个例外,表明我发送了很多消息并达到了限制,然后我无法发送.

当我在网站上输入我的Gmail时,我得到了一个我需要解决它的验证码,解决后我可以成功发送我的消息.

我的想法是导航到gmail.com我得到异常并填写我的Gmail和密码(以编程方式),并将验证码作为图像并通过代码解决它.

我可以实现我的想法吗?

c# captcha image

-3
推荐指数
1
解决办法
1786
查看次数

如何在 ASP.NET MVC 中获取请求参数

在我的一生中,我不知道如何在 ASP.NET MVC 中创建请求对象并拉入 Get 和 Post 参数。

我无法在动作构造函数中定义它们,我只想直接从请求中提取信息。

c# asp.net-mvc

-3
推荐指数
1
解决办法
5326
查看次数

在数组中间添加元素

如何在数组中间添加元素?我试过在谷歌搜索,但没有循环找不到办法做到这一点.任何人都可以通过提供代码片段来帮助我,但请不要建议使用循环,因为阵列很重,性能是这里的瓶颈.

编辑

实际上我希望每个奇数索引元素都被复制到偶数索引.

myarray[0] = "a";
myarray[1] = "b";
myarray[2] = "c";
Run Code Online (Sandbox Code Playgroud)

答案预期

myarray[0] = "a";
myarray[1] = "a";
myarray[2] = "b";
myarray[3] = "b";
myarray[4] = "c";
myarray[5] = "c";
Run Code Online (Sandbox Code Playgroud)

c# arrays winforms

-3
推荐指数
1
解决办法
6501
查看次数

C#没有正确计算小数结果

(5/15)*1185应该给395.

decimal Test = (5 / 15) * 1185;
Run Code Online (Sandbox Code Playgroud)

然而,这会返回0.我做错了什么?

c# decimal

-6
推荐指数
2
解决办法
789
查看次数

修复C#中的代码

我有以下C#代码:

double eps=0.1, low=1, y0=0, x, y, high, muchlat, answer, ribua;
Console.WriteLine("Enter x");
x = double.Parse(Console.ReadLine());
high = y = x;
muchlat = Math.Abs(y - y0) ;
if (x < 0)
{
    Console.WriteLine("X can't be less than zero, press any key to exit");

}
else if (muchlat > eps)
{

    while  (muchlat > eps)
    {
        Console.WriteLine(y);
        y0 = y;
        y = (high + low) /2;
        ribua = Math.Pow(y,2);
        if (ribua == x)
        {
            answer = x;
        }
        else if (ribua …
Run Code Online (Sandbox Code Playgroud)

c# variables local-variables

-11
推荐指数
1
解决办法
226
查看次数