C#使用正则判断IP地址

C#使用正则判断一个字符串是否为IP地址:

private boolean isIp(String ip) {
    String rex =
            "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
                    "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
                    "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
                    "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
    Pattern pattern = Pattern.compile(rex);
    Matcher matcher = pattern.matcher(ip);
    return matcher.find();
}

ASP.NET MVC缓存absoluteExpiration、slidingExpiration两个参数的疑惑

对C#缓存absoluteExpiration、slidingExpiration两个参数有点疑惑,看了很多资料终于搞明白 cache 中 absoluteExpiration,slidingExpiration 这两个参数的含义。

absoluteExpiration:用于设置绝对过期时间,它表示只要时间一到就过期,所以类型为System.DateTime,当给这个参数设置了一个时间时,slidingExpiration参数的值就只能为Cache.NoSlidingExpiration,否则出错;

slidingExpiration:用于设置可调过期时间,它表示当离最后访问超过某个时间段后就过期,所以类型为System.TimeSpan,当给这个参数设置了一个时间段时,absoluteExpiration的值就只能为Cache.NoAbsoluteExpiration,否则出错;

VS2017在使用VS2015编译的libcurl静态库时报错

VS2017在使用VS2015编译的libcurl静态库时报错,错误信息如下:

1>libcurld.lib(cookie.obj) : error LNK2019: unresolved external symbol ___iob_func referenced in function _Curl_cookie_init

1>libcurld.lib(url.obj) : error LNK2001: unresolved external symbol ___iob_func

1>libcurld.lib(mprintf.obj) : error LNK2001: unresolved external symbol ___iob_func

1>libcurld.lib(formdata.obj) : error LNK2001: unresolved external symbol ___iob_func

1> fatal error LNK1120: 1 unresolved externals


解决方案:

在stdafx.h中增加如下 代码:

FILE _iob[] = { *stdin, *stdout, *stderr };
extern "C" FILE * __cdecl __iob_func(void) { return _iob; }

再重新编译即可通过。

sql server游标

sql server游标的使用示例代码:

declare test_cursor cursor for
select  t1.baijiahao as bjh_name, t1.baijiahao_home_url as home_url, t2.category_name as domain from baijia_articles t1
inner join category t2
on t1.cat_id = t2.id
open test_cursor
declare @bjh_name nvarchar(50)
declare @home_url nvarchar(90)
declare @domain nvarchar(50)
fetch next from test_cursor into @bjh_name, @home_url, @domain
while @@fetch_status=0
begin
       
       if not exists ( select id from baijiahao where bjh_name=@bjh_name)  insert into baijiahao(bjh_name, home_url, domain) values(@bjh_name, @home_url, @domain)
       fetch next from test_cursor into @bjh_name, @home_url, @domain
end
close test_cursor
deallocate test_cursor