如何在nodejs中比较两个字符串源和目标与全名
How to compare two String Source and destination with fullname in nodejs
将两个字符串与第三个字符串进行比较 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);
}
我还有一个全名字符串。我有另外两个字符串。我想将源字符串与我的全名匹配,第一个单词目标将匹配或包含全名,而不是像源字符串那样的第一个字符串。
请帮帮我。
// 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)
如果我很好地理解了你的问题,并且你需要源是 FullName 的第一部分,destination 需要在 FullName 的其余部分,这个函数就可以了
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);
}
将两个字符串与第三个字符串进行比较 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);
}
我还有一个全名字符串。我有另外两个字符串。我想将源字符串与我的全名匹配,第一个单词目标将匹配或包含全名,而不是像源字符串那样的第一个字符串。
请帮帮我。
// 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)
如果我很好地理解了你的问题,并且你需要源是 FullName 的第一部分,destination 需要在 FullName 的其余部分,这个函数就可以了
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);
}