如何在nodejs中将两个String Source和destination与fullname进行比较

时间:2018-02-26 11:21:23

标签: javascript json node.js alexa-voice-service

比较两个字符串和第三个字符串,如JSON数组全名

var source = intentObj.slots.toPlazaName.value.toString(); // Jaipur 
var destination = intentObj.slots.fromPlazaName.value.toString(); // Kishangarh

与此"FullName": "Jaipur - Kishangarh Section",

匹配

我的回复

{
            "projectid": 10,
            "FullName": "Kishangarh -Ajmer- Beawar",
            "piu": "PIU-Ajmer",
            "NumberofLanes": "6L",
            "NHNo_New": "8",
            "NHNo_Old": "8",
            "Total_Length": 92,
            "state_name": "Rajasthan"
        },
        {
            "projectid": 15,
            "FullName": "Reengus - Sikar",
            "piu": "PIU-Sikar",
            "NumberofLanes": "4L",
            "NHNo_New": "52",
            "NHNo_Old": "11",
            "Total_Length": 44,
            "state_name": "Rajasthan"
        },
        {
            "projectid": 20,
            "FullName": "Rajsamand - Gangapur - Bhilwara",
            "piu": "PIU-Chittorgarh",
            "NumberofLanes": "4L",
            "NHNo_New": "758",
            "NHNo_Old": "76B",
            "Total_Length": 87.25,
            "state_name": "Rajasthan"
        },

我的创建功能

function findSourceDestination(source, destination, callback) {
    var matchPlazas = [];
    var projectFullName = [];

    for (var i = 0; i < nhai_response.GetALexDataInJSONResult.length; i++) {
        // console.log(nhai_response.GetALexDataInJSONResult[i]["FullName"]);
        if (nhai_response.GetALexDataInJSONResult[i]["FullName"].includes(source)) {
            // console.log("source " + nhai_response.GetALexDataInJSONResult[i]["FullName"]);
            projectFullName.push(nhai_response.GetALexDataInJSONResult[i]);
        }
    }

    for (var j = 0; j < projectFullName.length; j++) {
        if (projectFullName[j]["FullName"].includes(destination)) {
            console.log('----------------' +projectFullName[j]["FullName"] + '----------destination '+ destination +'------------');
            matchPlazas.push(projectFullName[j]);
        } 

    }

    callback(matchPlazas);
}

我有另一个全名字符串。我有另外两个字符串。我希望将源字符串与我的全名匹配第一个字的目的地将匹配或包含全名,而不是第一个字符串,如源字符串。

请帮帮我。

1 个答案:

答案 0 :(得分:0)

   // no search in progress, start our search at the end
                     _pos = Length - 1;
                 }
-                else if (!wasLive && String.IsNullOrWhiteSpace(search))
+                else if (!wasLive && string.IsNullOrWhiteSpace(search))
                 {
                     // Handles up up up enter up
                     // Do nothing
 @@ -167,7 +167,7 @@ private string MoveToPrevious(string search)

         private bool SearchDoesntMatch(string search)
         {
-            return !String.IsNullOrWhiteSpace(search) && GetHistoryText(_pos).IndexOf(search) == -1;
+            return !string.IsNullOrWhiteSpace(search) && GetHistoryText(_pos).IndexOf(search) == -1;
         }

         private string GetHistoryMatch(string search)