简体   繁体   English

使用 vscode 扩展 api 解析一个txt文档

[英]Parse through a txt document using vscode extension api

I'm trying to write a vscode extension where I can open a txt file, and parse through the contents of that txt file line by line, and be able to search for specific key words from each line.我正在尝试编写一个 vscode 扩展,我可以在其中打开一个 txt 文件,并逐行解析该 txt 文件的内容,并能够从每一行中搜索特定的关键词。 I've been looking at the TextDocument in the vscode api, but I'm a little confused on implementing it.我一直在查看 vscode api 中的 TextDocument,但我对实现它有点困惑。

How can I parse through a txt document line by line?如何逐行解析txt文档?

Thank you!谢谢!

const { activeTextEditor } = vscode.window;
if (!activeTextEditor) return;
const lines = activeTextEditor.document.getText().split('\n');
for (let i = 0; i < lines.length; i++) {
    const line = lines[i];
    console.log(i, line);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM