小编sno*_*s74的帖子

在sqlite中拆分FirstName和LastName

我在sqlite db中有一个名为[tblbook]的表,其中有一列[authors].我在sql中尝试做的是将作者值拆分为firstname和lastname并在lastname上对其进行排序.我找到了这个很棒的代码:

 SELECT substr(BookAuthor, 1, NULLIF(CHARINDEX(' ', BookAuthor) - 1, -1)) AS [FirstName],
   substr(BookAuthor, CHARINDEX(' ', BookAuthor) + 1, LEN(BookAuthor)) AS [LastName]
 FROM tblBook where _id=3
Run Code Online (Sandbox Code Playgroud)

它在MSSQL上运行完美,但sqlite没有charindex函数,因此失败了.

任何人都可以请善意,并告诉我什么应该是实现这一目标的最佳方法.

sqlite

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

从现有坐标mapkit查找最近的位置

我正在为拥有多家商店的客户开发iphone应用程序(目标C).我有一个数组中所有商店(20)的坐标(纬度,长度).

目前我正在考虑循环遍历商店的坐标数组,并获取用户当前位置到商店位置的距离,然后将它们添加到数组中并对最低距离进行排序.

这是一种正确的方法还是非常耗费资源?

最近的SOF问题就是这个问题,但它是在python中: 提取最近的商店

提前感谢您的建议.

objective-c mapkit ios

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

使用$ location.path()比较Angular中的URL

嗨我正在尝试使用登录服务为angular.js中的单页应用程序打开某些部分(即'call.html'不执行身份验证).

我想知道如何获取路径(http://www.example.com/app/#/call/1234),以便我可以比较它并重定向到"登录"页面,如果该页面不是'call.html '?

我的app.js中有以下代码似乎有效,但在Chrome中不起作用,我收到以下错误:

TypeError: $location.path(...).contains is not a function
Run Code Online (Sandbox Code Playgroud)

app.js.

app.run(['$rootScope', '$location', '$cookieStore', '$http',
    function ($rootScope, $location, $cookieStore, $http)
    {
        $rootScope.globals = $cookieStore.get('globals') || {};
        if ($rootScope.globals.currentUser)
        {
            $http.defaults.headers.common['Authorization'] = 'Basic' + $rootScope.globals.currentUser.authdata; // jshint ignore:line
        }
        $rootScope.$on('$locationChangeStart', function (event, next, current)
        {
            // redirect to login page if not logged in
            if($location.path().contains('call'))
            {
                return;
            }

            else
            {
                if ($location.path() !== '/login'  && !$rootScope.globals.currentUser && $location.path() !=='/')
                {
                    $location.path('/login');
                }
            }
        });
    }
]);
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题的任何帮助将不胜感激.

javascript angularjs

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

无法json_decode

我将数据从Vb.net客户端发布到PHP rest api但由于某种原因json_decode不能处理传递的字符串.发布到服务器的代码是:

        Dim payload As String = "{""key"":""Test"",""bookings"":" & txtUpload.Text & "}"

        Dim request As WebRequest = WebRequest.Create(String.Format(baseAPIImportUrl))
        ' Set the Method property of the request to POST.  
        request.Method = "POST"
        ' Create POST data and convert it to a byte array.  
        Dim byteArray() As Byte = Encoding.UTF8.GetBytes(payload)
        ' Set the ContentType property of the WebRequest.  
        request.ContentType = "application/x-www-form-urlencoded"
        ' Set the ContentLength property of the WebRequest.  
        request.ContentLength = byteArray.Length
        ' Get the request stream.  
        Dim dataStream As Stream …
Run Code Online (Sandbox Code Playgroud)

php arrays json

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

在C#中传递枚举数组

我需要允许多个角色在C#Web API的控制器中访问方法。

I have a custom AuthorizeAttribute which takes an enum of role type, how can I make it so it accepts multiple enums ie. a variable length array of enums.

This is the code I have written for the Attribute:

private readonly RoleEnum roleInApplication;

public ScopeAuthorizeAttribute(RoleEnum roleInApplication)
{
    this.roleInApplication = roleInApplication;
}

public override void OnAuthorization(HttpActionContext actionContext)
{
    base.OnAuthorization(actionContext);
    .......
    var relatedPermisssionRole = (db call to get the rolename..etc)
    RoleEnum role;
    if (Enum.TryParse(relatedPermisssionRole, out role) && role == …
Run Code Online (Sandbox Code Playgroud)

c# authorize-attribute

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

Javascript中的条件array.join

我有一个字符串数组,我想将它们显示为逗号分隔的字符串,但在最后一个元素上添加“ and”。例如我有

var fruits = ["Banana", "Orange", "Apple", "Mango"];
var energy = fruits.join(' ,'); 
Run Code Online (Sandbox Code Playgroud)

输出

'Banana, Orange, Apple, Mango'
Run Code Online (Sandbox Code Playgroud)

有什么办法我给最后一个单词加上“和”,以便输出

'Banana, Orange, Apple and Mango'
Run Code Online (Sandbox Code Playgroud)

javascript arrays

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

如何同时删除括号和括号内带有空白的文本(如果存在)?

我正在尝试使用以下代码在PHP中清除字符串,但是我不确定如何在使用空格之前同时删除括号和括号内的文本。

我使用的代码是:

$string = "Deadpool 2 [Region 4](Blu-ray)";
echo preg_replace("/\[[^)]+\]/","",$string); 
Run Code Online (Sandbox Code Playgroud)

我得到的输出是:

Deadpool [](Blu-ray)
Run Code Online (Sandbox Code Playgroud)

但是,所需的输出是:

Deadpool 2
Run Code Online (Sandbox Code Playgroud)

使用来自解决方案这个这个问题,目前还不清楚如何删除这两个一个类型匹配,另一个同时在他们面前卸下可选空白。

php regex

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