问题列表 - 第15934页

如何将{1,0}与正则表达式匹配?

? or `{0,1}` 
Run Code Online (Sandbox Code Playgroud)

必要时会匹配一些模式,但现在我想反向做.

说,如果有必要,请不要匹配.

有人得到我的意思有解决方案吗?

regex

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

添加重复项时抛出异常的.NET集合

.NET框架(3.5)中是否有一个集合(除了字典),在添加副本时会抛出异常?

HashSet不会抛出异常:

HashSet<string> strings = new HashSet<string>();
strings.Add("apple");
strings.Add("apple");
Run Code Online (Sandbox Code Playgroud)

而词典确实:

Dictionary<string, string> dict = new Dictionary<string, string>();
dict.Add("dude", "dude");
dict.Add("dude", "dude"); //throws exception
Run Code Online (Sandbox Code Playgroud)

编辑:有没有(键,值)的集合这样做?如果可能的话我也想要AddRange ......

我推出了自己的:

public class Uniques<T> : HashSet<T>
{

    public Uniques()
    { }

    public Uniques(IEnumerable<T> collection)
    {
        AddRange(collection);
    }

    public void Add(T item)
    {
        if (!base.Add(item))
        {
            throw new ArgumentException("Item already exists");
        }
    }


    public void AddRange(IEnumerable<T> collection)
    {
        foreach (T item in collection)
        {
            Add(item);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

.net collections unique duplicates

10
推荐指数
1
解决办法
4863
查看次数

获取html文件中使用的所有CSS

我必须得到使用JavaScript的HTML文件中使用的所有CSS样式.

<html>
    <head>
        <style type="text/css">
            body {
                border: 1px solid silver;
            }
            .mydiv{
                color: blue;
            }
        </style>
    </head>
    <body>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

如果上面的代码是我的HTML,我必须在head中编写一个JavaScript函数,它返回一个这样的字符串.

body {
    border: 1px solid silver;
}
.mydiv {
    color: blue;
}
Run Code Online (Sandbox Code Playgroud)

有可能吗?

html javascript

8
推荐指数
3
解决办法
9731
查看次数

使用Javascript刷新页面很难

我有一个问题,我正在打开一个弹出窗口,使用javascript然后弹出一个窗口,在那里我对css文件进行了更改,当我点击关闭以下javascript正在用于刷新窗口打开页面

window.opener.location.reload();
window.close();
Run Code Online (Sandbox Code Playgroud)

但是css仍然在浏览器中缓存,在下次刷新之后这只会消失.有没有办法我可以使用javascript刷新开启页面?

javascript

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

libxml2错误处理

我正在用C++编写一个关于libxml2的小包装器,我正在尝试解决如何处理错误.现在,让我们说我只想打印出来.这是我目前得到的:

我的错误处理功能:

void foo(void *ctx, const char *msg, ...) {
  cout << msg << endl;
  return;
}
Run Code Online (Sandbox Code Playgroud)

初始化如下:

xmlGenericErrorFunc handler = (xmlGenericErrorFunc)foo;
initGenericErrorDefaultFunc(&handler);
Run Code Online (Sandbox Code Playgroud)

但是,如果我解析一个糟糕的XPath,我得到这个输出:

%s

没有错误处理代码,我得到这个:

XPath error : Invalid expression
//.@foobar
    ^

显然,最终我的错误处理将不仅仅打印出错误消息(它会将其记录到数据库或其他东西),但是现在 - 我怎样才能获得该错误字符串?

c c++ libxml2

1
推荐指数
1
解决办法
6267
查看次数

我可以从ac#.net dll调用vb.net dll吗?

简单的是/否问题:我可以在自己的C#dll编译的ac#函数中调用在vb.net dll中编译的vb.net函数吗?在同一个应用程序中运行.

.net

0
推荐指数
3
解决办法
245
查看次数

如何使用PHP在foreach循环中分隔行

使用以下代码显示我的推特个人资料中的朋友列表.我喜欢一次只加载一定数量,比如说20,然后在第一个1-2-3-4-5的底部提供分页链接(不过很多除以限制)最后

$xml = simplexml_load_string($rawxml);

foreach ($xml->id as $key => $value) 
{
    $profile           = simplexml_load_file("https://twitter.com/users/$value");
    $friendscreenname  = $profile->{"screen_name"};
    $profile_image_url = $profile->{"profile_image_url"};

    echo "<a href=$profile_image_url>$friendscreenname</a><br>";
}
Run Code Online (Sandbox Code Playgroud)

******更新******

if (!isset($_GET['i'])) {
    $i = 0;
} else {
    $i = (int) $_GET['i'];
}

$limit  = $i + 10;
$rawxml = OauthGetFriends($consumerkey, $consumersecret, $credarray[0], $credarray[1]);
$xml    = simplexml_load_string($rawxml);

foreach ($xml->id as $key => $value)
{

    if ($i >= $limit) {
        break;
    }

    $i++;
    $profile           = simplexml_load_file("https://twitter.com/users/$value");
    $friendscreenname  = $profile->{"screen_name"};
    $profile_image_url = $profile->{"profile_image_url"};

    echo "<a href=$profile_image_url>$friendscreenname</a><br>"; …
Run Code Online (Sandbox Code Playgroud)

php pagination simplexml

4
推荐指数
1
解决办法
6489
查看次数

使用Visual Studio命令提示符工具

如何Programs | MS Visual Studio 2008 | Visual Studio Tools | Visual Studio 2008 Command Prompt从任何命令提示符(即不调用vcvarsall.bat)或程序中使用VS命令提示符()中包含的工具?

command-line visual-studio

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

按名称而不是索引获取document.styleSheets?

document.styleSheets与索引一起使用,
但是如果我想将stylesheet.insertRule与特定的CSS文件一起使用呢?

我知道文件的名称,它被注入页面并在某些时候通过JS注入.

javascript css

27
推荐指数
3
解决办法
4万
查看次数

删除ThreadPoolExecutor的所有排队任务

我有关于ThreadPoolExecutor的这个相当简单的问题.我有以下情况:我必须从队列中使用对象,为它们创建适当的工作人员任务并将它们提交给ThreadPoolExecutor.这很简单.但在关闭情况下,许多工作人员可能会排队等待执行.由于其中一个任务可能运行了一个小时,并且我希望相对快速地正常关闭应用程序,我想从ThreadPoolExecutor中丢弃所有排队的任务,而已经处理的任务应该正常完成.

ThreadPoolExecutor文档有一个remove()方法,但只允许删除特定的任务.purge()仅适用于已取消的Future任务.我的想法是清除队列中包含所有排队的任务.ThreadPoolExecutor提供对此内部队列的访问,但文档指出:

方法getQueue()允许访问工作队列以进行监视和调试.强烈建议不要将此方法用于任何其他目的.

所以抓住这个队列并清除它不是一个选择.此外,该文档的片段说:

当大量排队的任务被取消时,两个提供的方法remove(java.lang.Runnable)和purge()可用于协助存储回收.

怎么样?当然,我可以维护我提交给执行程序的所有任务的列表,在关闭的情况下,我遍历所有条目并使用remove()方法将它们从ThreadPoolExecutor中删除......但是...来吧,这是一个浪费记忆力和维护这份清单的麻烦.(例如,删除已执行的任务)

我感谢任何提示或解决方案!

java multithreading executorservice executor threadpool

26
推荐指数
4
解决办法
2万
查看次数