Home > Web Front-end > JS Tutorial > js reads configuration file self-writing_javascript skills

js reads configuration file self-writing_javascript skills

WBOY
Release: 2016-05-16 17:00:42
Original
1281 people have browsed it

A program I wrote using js to read the configuration file
D:Useful StuffJavascriptmytest.txt
The content of the file is as follows

Copy code The code is as follows:

[plugin_page_search]
wholeword=0
matchcase=1
hightlight=1
total=1

[data]
up=85
down=5

Copy code The code is as follows:

var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile("D:\Useful Stuff\Javascript\mytest.txt",1);
var s = "";
while (!f.AtEndOfStream)
{
s = f.ReadLine();
}
f.Close();

function getINI(item,key)
{
new RegExp("\[" item "\](. )").exec(s);
var str=RegExp.$1;
var reg2=/(w )=(d )/;
var keyValue={};
str.replace(reg2,function(a,b,c){
keyValue[b]=c ;
});
return keyValue[key];
}
alert(getINI("data","up"));
alert(getINI("plugin_page_search","hightlight "));
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template