我有一个config.txt文件,如下所示:
protected getLocalFilename(): string {
const fileNameMatches: string[]|null = this.filePath.match(/\/(.+\.js)$`/);
if (Boolean(fileNameMatches) && fileNameMatches[0] !== null) { // TS2531: Object is possibly 'null'
return fileNameMatches[0]; // TS2531: Object is possibly 'null'
}
else {
throw Error("No filename found during regex matching")
}
}
我正在尝试阅读其内容,以便稍后处理。但是,当我尝试程序并打印文件内容时,即使我自己终止字符串,其输出的字符也比文件中的字符更多。好像文件的长度被程序高估了。这是printf的输出:
if (typeOf fileNameMatches !== "null") {
显然,两个字符 df 不应存在。我究竟做错了什么。我在Google周围搜索,但找不到清晰的答案。这是我的C程序:
2
2
[3, 8]
[4, 2]-[12, 7]
[1, 10]-[12, 1]