小编Jes*_*lam的帖子

除非在单个带引号的字符串中,否则如何按空格分割字符串?

我正在寻找一种解决方案来拆分包含以下格式的文本的字符串:

"abcd efgh 'ijklm no pqrs' tuv"
Run Code Online (Sandbox Code Playgroud)

这将产生以下结果:

['abcd', 'efgh', 'ijklm no pqrs', 'tuv']
Run Code Online (Sandbox Code Playgroud)

换句话说,除非在单个带引号的字符串中,否则它将按空格分割.我认为可以使用.NET regexps使用"Lookaround"运算符,特别是平衡运算符.我不太了解Perl.

regex perl split

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

如何查看您是否两次点击相同的元素?jQuery的

如何检测用户是否点击了相同的div?

我试过这个没有成功:

    _oldthis = null;

    var _this = $(this);

    if(_oldthis == _this) {
        alert('You clicked this last');
    }

    _oldthis = _this;
Run Code Online (Sandbox Code Playgroud)

jquery this jquery-selectors

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

GetOternalLoginInfo在Google OWIN提供程序上返回'null'

我从Visual Studio 2013获得了一个近乎完整的ASP.NET MVC模板应用程序.它是使用以下设置创建的:

创建>项目> Web> ASP.NET Web应用程序>确定> MVC,个人用户帐户>确定

我正在尝试使用OWIN Google提供商登录并遇到问题.

OWINs Configuration方法如下所示:

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login")
        });

        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

        var google = new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions
        {
            ClientId = "xxxxx.apps.googleusercontent.com",
            ClientSecret = "xxxxxxxxx-yyyyyyyyy"
        };

        google.Scope.Add("profile");
        google.Scope.Add("email");

        app.UseGoogleAuthentication(google);
Run Code Online (Sandbox Code Playgroud)

我点击Google网页上的提供商按钮,通过谷歌进行身份验证,然后返回参考ExternalLoginCallback.此时,该过程在此行中出现故障:

var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

loginInfo是null,它将我重定向回登录页面,没有任何可见的错误.

asp.net oauth owin katana

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

非聚集索引中是否有主键?

为了尝试为我的数据库做出最好的索引选择,我注意到了一些我想要解决的特定行为.

观察下表和相应的索引(SQL Server 2005):

CREATE TABLE demo
(
 id INT PRIMARY KEY IDENTITY,
 name NVARCHAR(50) NOT NULL,
 password BINARY(20) NOT NULL
);

CREATE NONCLUSTERED INDEX idx_demo_foo ON demo ( name, password );
Run Code Online (Sandbox Code Playgroud)

在这种情况下,如果我执行以下查询...

SELECT id FROM demo
WHERE name = @0
AND   password = @1;
Run Code Online (Sandbox Code Playgroud)

...仅发生非聚集索引查找.这让我很奇怪,因为我没有明确地将id添加到非聚集索引.

sql t-sql sql-server-2005

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

无法转换参数 - 转换失去限定符

我经常被const正确性所困扰,这似乎也不例外.请告诉我为什么以下代码不会编译:

class string_token_stream
{
    public:

    typedef wchar_t* string_type;

    string_token_stream(const string_type input_string)
        : _input_string(input_string)
    {
    }

    private:

    const string_type _input_string;
};

int main(int argc, char **argv)
{
    const wchar_t *str = get_a_string_somewhere();
    string_token_stream sts(str);
    //                      ^------ Compile-time error C2664.
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

给出的错误是:

error C2664: 'string_token_stream::string_token_stream(const string_token_stream::string_type)' : cannot convert parameter 1 from 'const wchar_t *' to 'const string_token_stream::string_type'
1>          Conversion loses qualifiers
Run Code Online (Sandbox Code Playgroud)

我正在编译Visual C++ 2010 Express.可根据要求提供其他编译/链接器选项.

c++ visual-c++

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

如何从MVC3中的javascript调用Controller方法?

我使用MVC3架构,c#.net.当焦点更改为下一个字段即密码字段时,我需要立即将文本框内容(用户ID)与数据库进行比较.所以我想在用户ID字段中使用onblur事件,然后调用Controller方法.谁能告诉我如何处理这个问题?作为一个新手,代码片段受到高度赞赏.

提前致谢,

普拉香特

.net javascript c# ajax asp.net-mvc-3

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

枚举PSCustomObject作为键/值对

我正在调用Invoke-RestMethod一个返回JSON的URI,如下所示:

{
  "01": {"ID":1, "Name":"Foo"},
  "02": {...},
  "03": {...}
}
Run Code Online (Sandbox Code Playgroud)

我最终得到PSCustomObject的属性名称是键中的数字,值是对象图,但我想将对象视为键/值对的列表(即:字典).我试过了:

(Invoke-RestMethod -Uri $uri) | foreach-object {
  $_.ID
  $_.Key.ID
}
Run Code Online (Sandbox Code Playgroud)

等等; 但后来意识到这Foreach-Object只是迭代一次; 来自的返回值Invoke-RestMethod不是IEnumerable

如何在结果对象中获取属性和值的集合?

powershell

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

跨多个子域的URL路由

我发现自己处境艰难.我们正在开发一个ASP.NET MVC 2应用程序,它由多个部分组成.将这些部分跨越多个子域是一个设计目标.每个子域都有自己的控制器.

挑战在于我们的托管服务提供商的控制面板允许两种形式的子域重定向,而且它们都不适合这个账单.选择是:

  • 重定向到URL.选择是否重定向到相对于请求URL的确切目的地或目的地.

  • 重定向到我的托管空间中的特定文件夹.

我将尝试说明预期的行为.假设默认路由是{controller}/{action}/{id},我希望URL http://subdomain.welcome.com/a/b由MVC应用程序处理http://welcome.com/subdomain/a/b.

URL重定向可以解决此问题,除了用户在浏览器中看到URL更改的事实.我们不希望客户端看到重定向发生.

重定向到我们的MVC应用程序根文件夹根本不起作用.该应用程序不会接收请求,IIS会传回4xx错误.

编辑:

为了找到答案,我会简化一下."重定向到URL"没有做我想要的,所以留下重定向到一个文件夹.

如果我将子域重定向到我的MVC应用程序的根文件夹并且IIS不会接收请求,这是IIS还是我的提供商的限制?

c# asp.net asp.net-mvc url-routing

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

SQL Server设计中是否必须使用"主键"?

观察下表模型:

CREATE TABLE [site].[Permissions] (
    [ID]     INT REFERENCES [site].[Accounts]( [ID] ) NOT NULL,
    [Type]   SMALLINT NOT NULL, 
    [Value]  INT NULL
);
Run Code Online (Sandbox Code Playgroud)

site.Accounts-> site.Permissions是一对多关系,因此由于PK强加的唯一性,'ID'不能成为主键.

使用WHERE [ID] = ?子句选择行,因此添加一个虚假的IDENTITY列并使其成为PK会产生额外的磁盘空间.

据我所知,目标平台 - SQL Server(2008) - 不支持复合PK.这些都加起来我的问题:如果没有使用主键,那么有什么不对吗?或者可能更正确的事情?

t-sql sql-server database-design

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