如何在 ASP.Net 解决方案中搜索一堆关键字
How to search a bunch of keywords in an ASP.Net solution
我有大约600个关键字,需要在非常庞大的.Net解决方案中搜索所有这些关键字才能找出答案其中哪一个从未被使用过。有没有什么快速的方法可以完成这项任务,而不用使用 ctrl + F(在 Visual studio 中)一个一个地找到它们?非常感谢您的帮助。
终于找到解决办法了。我 post 它,也许它对某人有用。
我创建了一个简单的 Node.js
项目并安装了一个包 (find-in-files),用于在任何 sub-directory 中跨多个文件搜索文本模式。所以这是代码:
const seeker = require("find-in-files");
const fs = require('fs');
//read the file containing 600 stored procedure names
fs.readFile('600SPs.txt', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
//split the string based on new lines and put each keyword in the array.
const lines = data.split(/\r?\n/);
//make sure there is no white spaces
const trimmedLines = lines.map(line=>line.trim());
//show a message to user to wait till async task is finished.
console.log("please wait...");
//create a regex to match any of the keywords while searching files.
const boundryTrimmedLines = trimmedLines.map(value=>(`\b${value}\b`));
const regExText = boundryTrimmedLines.join("|");
//call find function of find-in-files package which can search through all of the files
// in the given directory and its sub directories that have .cs format
seeker.find(regExText, "D:\TestProj\ParentDir",".cs$")
.then(res=>{
//res is based on files pathes having the keywords
//what is intended is keywords based on the file pathes
//so res format should be modified.
var rawAnswers = [];
Object.keys(res).map(key=>{
const rawElement = {
address:key,
matchedCases:res[key].matches
};
rawAnswers.push(rawElement);
})
var finalAnswer = [];
trimmedLines.map(word=>{
let finalItem = {
word,
addresses:[]
}
rawAnswers.map(rawAnswer=>{
if(rawAnswer.matchedCases.some(i=>i==word)){
finalItem.addresses.push(rawAnswer.address);
}
})
finalAnswer.push(finalItem);
})
//write finalAnswer to a json file
fs.writeFile("answer.json",JSON.stringify(finalAnswer,null,2),function(error){
if(error)
console.log("not created.");
else
console.log("created successfully.")
})
})
});
有关详细信息,这是 600SPs.txt
文件的一部分(每个 SP
名称,放在一行中):
New9090_Ras
New9090_Ras2
NewDrawingData
NewDrawingDataSelect
ProcedureName
R_CLVQ
RFM_py_AEKAL
SaveDynamicMenu
setFinalUpdateMenueId
这是最终结果的一部分 (answer.json
) :
我有大约600个关键字,需要在非常庞大的.Net解决方案中搜索所有这些关键字才能找出答案其中哪一个从未被使用过。有没有什么快速的方法可以完成这项任务,而不用使用 ctrl + F(在 Visual studio 中)一个一个地找到它们?非常感谢您的帮助。
终于找到解决办法了。我 post 它,也许它对某人有用。
我创建了一个简单的 Node.js
项目并安装了一个包 (find-in-files),用于在任何 sub-directory 中跨多个文件搜索文本模式。所以这是代码:
const seeker = require("find-in-files");
const fs = require('fs');
//read the file containing 600 stored procedure names
fs.readFile('600SPs.txt', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
//split the string based on new lines and put each keyword in the array.
const lines = data.split(/\r?\n/);
//make sure there is no white spaces
const trimmedLines = lines.map(line=>line.trim());
//show a message to user to wait till async task is finished.
console.log("please wait...");
//create a regex to match any of the keywords while searching files.
const boundryTrimmedLines = trimmedLines.map(value=>(`\b${value}\b`));
const regExText = boundryTrimmedLines.join("|");
//call find function of find-in-files package which can search through all of the files
// in the given directory and its sub directories that have .cs format
seeker.find(regExText, "D:\TestProj\ParentDir",".cs$")
.then(res=>{
//res is based on files pathes having the keywords
//what is intended is keywords based on the file pathes
//so res format should be modified.
var rawAnswers = [];
Object.keys(res).map(key=>{
const rawElement = {
address:key,
matchedCases:res[key].matches
};
rawAnswers.push(rawElement);
})
var finalAnswer = [];
trimmedLines.map(word=>{
let finalItem = {
word,
addresses:[]
}
rawAnswers.map(rawAnswer=>{
if(rawAnswer.matchedCases.some(i=>i==word)){
finalItem.addresses.push(rawAnswer.address);
}
})
finalAnswer.push(finalItem);
})
//write finalAnswer to a json file
fs.writeFile("answer.json",JSON.stringify(finalAnswer,null,2),function(error){
if(error)
console.log("not created.");
else
console.log("created successfully.")
})
})
});
有关详细信息,这是 600SPs.txt
文件的一部分(每个 SP
名称,放在一行中):
New9090_Ras
New9090_Ras2
NewDrawingData
NewDrawingDataSelect
ProcedureName
R_CLVQ
RFM_py_AEKAL
SaveDynamicMenu
setFinalUpdateMenueId
这是最终结果的一部分 (answer.json
) :