ini配置文件的读取
LANG] language=zh-Hans [LOGIN] serverIP=你需要的服务器IP地址 userName=chaoyue userPass=000000 [MAPINFO] web1lat=34.2638 web1lng=108.9469 web2lat=34.2638 web2lng=108.9469 web1zoom=10 web2zoom=10 web1southWestlat=10.055402736564236 web1northEastlat=53.067626642387374 web1southWestlng=58.798828125 web1northEastlng=159.08203125 web2southWestlat=23.32208001137843 web2northEastlat=43.96119063892024 web2southWestlng=81.298828125 web2northEastlng=136.669921875
节
参数(键=值)
注解
注解使用分号表示(;)。在分号后面的文字,直到该行结尾都全部为注解。 ; comment textINI文件的数据格式的例子(配置文件的内容) [Section1 Name] KeyName1=value1 KeyName2=value2 ... [Section2 Name] KeyName21=value21 KeyName22=value22 其中: [Section1 Name]用来表示一个段落。 因为INI文件可能是项目中共用的,所以使用[Section Name]段名来区分不同用途的参数区。例如:[Section1 Name]表示传感器灵敏度参数区;[Section2 Name]表示测量通道参数区等等。 KeyName1=value1 用来表示一个参数名和值。 比如: 7033=50 7034=51 其中: 7033表示某传感器名,50表示它的灵敏度值。 7034表示另一只传感器名,51表示它的灵敏度值。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.Text.RegularExpressions; using System.Runtime.InteropServices; namespace 你的命名空间 {class CIni{//声明读写INI文件的API函数 public string path;public CIni(){}[DllImport("kernel32")]private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);[DllImport("kernel32")]private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);/// <summary>/// ini文件编写器/// </summary>/// <param name="section">查找ini文件的节点[]名</param>/// <param name="key">节点下边的键</param>/// <param name="val">节点的值</param>/// <param name="filePath">来自的文件</param>public void WriterINI(string section, string key, string val,string filePath){path = System.Environment.CurrentDirectory + "\\" + filePath;WritePrivateProfileString(section, key, val, path);}/// <summary>/// 读取Ini文件/// </summary>/// <param name="section">获得节点</param>/// <param name="key">节点下边的键</param>/// <param name="filePath">文件路径</param>/// <returns>返回的值</returns>public string ReadINI(string section, string key, string filePath){path = System.Environment.CurrentDirectory + "\\" + filePath;StringBuilder temp = new StringBuilder(255);GetPrivateProfileString(section, key, "", temp, 255, path);return temp.ToString().Trim();}} } 用法:/// <summary>/// 读取Ini文件/// </summary>/// <param name="strConet">字段</param>/// <param name="order"></param>private void WriterINI(string strConet, int order){GetNextToken(ref strConet, ",");CIni ini = new CIni();if (order == 1){ini.WriterINI("MAPINFO", "web1lat", GetNextToken(ref strConet, ","), "Setting.ini");ini.WriterINI("MAPINFO", "web1lng", GetNextToken(ref strConet, ","), "Setting.ini");ini.WriterINI("MAPINFO", "web1zoom", GetNextToken(ref strConet, ","), "Setting.ini");ini.WriterINI("MAPINFO", "web1southWestlat", GetNextToken(ref strConet, ","), "Setting.ini");ini.WriterINI("MAPINFO", "web1northEastlat", GetNextToken(ref strConet, ","), "Setting.ini");ini.WriterINI("MAPINFO", "web1southWestlng", GetNextToken(ref strConet, ","), "Setting.ini");ini.WriterINI("MAPINFO", "web1northEastlng", GetNextToken(ref strConet, ","), "Setting.ini");}else{ini.WriterINI("MAPINFO", "web2lat", GetNextToken(ref strConet, ","), "Setting.ini");ini.WriterINI("MAPINFO", "web2lng", GetNextToken(ref strConet, ","), "Setting.ini");ini.WriterINI("MAPINFO", "web2zoom", GetNextToken(ref strConet, ","), "Setting.ini");ini.WriterINI("MAPINFO", "web2southWestlat", GetNextToken(ref strConet, ","), "Setting.ini");ini.WriterINI("MAPINFO", "web2northEastlat", GetNextToken(ref strConet, ","), "Setting.ini");ini.WriterINI("MAPINFO", "web2southWestlng", GetNextToken(ref strConet, ","), "Setting.ini");ini.WriterINI("MAPINFO", "web2northEastlng", GetNextToken(ref strConet, ","), "Setting.ini");}} ////GetNextToken方法private string GetNextToken(ref string strContent, string strDelim){string str = "";int idx = strContent.IndexOf(strDelim, 0, strContent.Length);if (idx > 0){str = strContent.Substring(0, idx);strContent = strContent.Remove(0, idx + 1);}else{str = strContent;}return str;}/// <summary>/// 设置ini文件/// </summary>private void SetCenter(){CIni ini = new CIni();string strweb1lat = ini.ReadINI("MAPINFO", "web1lat", "Setting.ini");string strweb1lng = ini.ReadINI("MAPINFO", "web1lng", "Setting.ini");string strweb1zoom = ini.ReadINI("MAPINFO", "web1zoom", "Setting.ini");string strweb2lat = ini.ReadINI("MAPINFO", "web2lat", "Setting.ini");string strweb2lng = ini.ReadINI("MAPINFO", "web2lng", "Setting.ini");string strweb2zoom = ini.ReadINI("MAPINFO", "web2zoom", "Setting.ini");//你的方法写在这里..... }
转载于:https://www.cnblogs.com/imeiba/p/5698019.html
ini配置文件的读取相关推荐
- Go语言从INI配置文件中读取需要的值
生命不息,学习不止 题外话 INI配置文件 从 INI 文件中取值 getValue() 函数 你以为结束了 题外话 清晨第一缕阳光打在我的脸上,我从我席梦思床垫上爬起,拿起我的iPhone56,定了 ...
- 用python打印输出ini配置文件,把测试数据写进ini文件里
读取ini配置文件: #读取ini配置文件 import configparser #导入类库 cfg=configparser.ConfigParser() #声明一个句柄(示例) cfg.read ...
- python读取配置文件 分段_Python3读写ini配置文件的示例
ini文件即Initialization File初始化文件,在应用程序及框架中常作为配置文件使用,是一种静态纯文本文件,使用记事本即可编辑. 配置文件的主要功能就是存储一批变量和变量值,在ini文件 ...
- c读取ini配置文件_Go-INI - 超赞的Go语言INI文件操作库
INI 文件(Initialization File)是十分常用的配置文件格式,其由节(section).键(key)和值(value)组成,编写方便,表达性强,并能实现基本的配置分组功能,被各类软件 ...
- java inireader_java读取配置文件 Java中如何设置读取ini配置文件?
Java读取配置文件的几种方法以及路径问题看透,心静,锁份幽静,将自己填埋在那里,任窗外灯红酒绿,草长莺飞,让那颗疲惫的心,静静地栖息在流水盈盈里,抛却尘世累累. java 怎么读取web jar中的 ...
- python读取配置文件存在某配置_Python读取ini配置文件的方式
ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(section), 每个节可以有多个参数(键=值).使用的配置 ...
- 用C读取INI配置文件 (可在linux平台上用)
/*c语言实现,可在linux平台上用了,在Windows下可以用GetPrivateProfileString或GetPrivateProfileInt方便读取.ini配置文件内容,但是在Linux ...
- Java 读取 INI 配置文件的方法
INI 配置文件是 Windows 以前非常喜欢使用的一种配置文件格式,形如: [GLOBAL] path = c:\appdata [JDBC] driver = com.mysql.jdbc.Dr ...
- c#读取ini配置文件、将配置数据保存至ini文件
全栈工程师开发手册 (作者:栾鹏) c#教程全解 c#读取ini配置文件.将配置数据保存至ini文件 测试代码 static void Main() {string value = readini(& ...
最新文章
- Android开发 - 解决DialogFragment在全屏时View被状态栏遮住的问题
- 内核分析PE获取DLL导出函数地址
- ElasticSearch中文分词器-IK分词器的使用
- 我学的技术,过时?被淘汰?
- C++设计模式-使用Qt框架采用简单工厂模式实现商城打折满减案例
- -bash-退出_为什么这么多开发人员在找到工作之前就退出了。 请-不要。
- Zend Studio 打开时提示 Failed to create the Java Virtual Machine
- Linux 5.10将解决2038年问题
- 机器学习笔记-回归评价指标scikit-learn
- 【2022-01-06】JS逆向之QCC请求头参数
- HDTunePro v5.00 硬盘专业工具(绿色版)
- XML解析—开源XOM类库
- java pacs上传服务_PACS千万家,好看耐用第一家---基于JAVA开发的跨平台PACS系统
- char在mysql中的意思_mysql中char表示什么意思
- ixgbe网卡驱动 Ⅳ----收发包流程详解
- 如何修改安卓软件的图标和名字
- 【华人学者风采】李凯 普林斯顿大学
- 解决ssh packet_write_wait: Connection to 192.168.xx.xx port 22: Broken pipe的问题
- 二维矩阵乘法、矩阵转置、 矩阵与向量乘法(java实现)
- Waiting for application to come online: com.example.andyyuan.androidmui.test | com.example.andyyuan.