2

Compare two string with third-string like JSON Array full name

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

match with this "FullName": "Jaipur - Kishangarh Section",

My response

{
            "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"
        },

my create function

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);
}

I have full name string another. I have two another string. I want to match source string with my full name first-word destination will match or contain with full name, not the first string like the source string.

Please help me.

Sonu Kumar
  • 969
  • 1
  • 11
  • 36

2 Answers2

1

If I understood well your questions, and you need the source to be the first part of FullName, and destination needs to be in the rest of FullName, this function makes it

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

    for (var i = 0; i < nhai_response.GetALexDataInJSONResult.length; i++) {
        let fullName = nhai_response.GetALexDataInJSONResult[i]["FullName"];
        let fullNameParts = fullName.split("-");
        if (fullNameParts[0].trim().includes(source) && fullName.includes(fullName)) {
            matchPlazas.push(nhai_response.GetALexDataInJSONResult[i]);
        }
    }

    callback(matchPlazas);
}
David Vicente
  • 3,091
  • 1
  • 17
  • 27
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)