using System;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Runtime.InteropServices;
using System.Text; namespace File_IO
{ public class inifile
{
public string Path;
public string Section;
public string Key;
public string value;
public inifile(string path)
{
this.Path=path;
}
#region 声明读写INI的API函数
[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 defVal, StringBuilder retVal, int size, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string defVal, Byte[] retVal, int size, string filePath);
#endregion

C#代码实现如下

 public void openorcreat()
{
if (File.Exists(Path))
{
}
else
{
File.Create(Path);
}
}

C#代码实现

public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(); int i = GetPrivateProfileString(Section, Key, "", temp, , this.Path);
return temp.ToString();
}
public string IniReadValue()
{
return IniReadValue(Section, Key);
}

c#代码实现

 public void IniWriteValue()
{
IniWriteValue(Section, Key, value);
}
public void IniWriteValue(string Section, string Key, string value)
{
WritePrivateProfileString(Section, Key, value, this.Path);
}

C#代码实现

 public void removeKey(string Section, string Key)
{
IniWriteValue(Section, Key, null);
}

C#代码实现

public string[] GetKeyNames(string Section)
{
byte[] allKeys = IniReadValues(Section, null);
string[] keylist;
string keynames;
ASCIIEncoding scii = new ASCIIEncoding();
keynames = scii.GetString(allKeys);
keylist = keynames.Split(new char[] { '\0' });
return keylist;
}

C#实现

public string[] GetSectionNames()
{
byte[] allSection = IniReadValues(null, null);
string[] sectionList;
string sections;
ASCIIEncoding ascii = new ASCIIEncoding();
sections = ascii.GetString(allSection);
sectionList = sections.Split(new char[] { '\0' });
return sectionList;
}

C#代码实现

public void removeSection(string Section)
{
IniWriteValue(Section, null, null);
}

  

【LABVIEW到C#】1》ini的操作的更多相关文章

  1. LabVIEW之生产者/消费者模式--队列操作 彭会锋

    LabVIEW之生产者/消费者模式--队列操作 彭会锋 本文章主要是对学习LabVIEW之生产者/消费者模式的学习笔记,其中涉及到同步控制技术-队列.事件.状态机.生产者-消费者模式,这几种技术在在本 ...

  2. ini文件操作

    Config.ini 文件操作 [SYS] sysname=hy company=hyhy tel=2 using System; using System.Collections.Generic; ...

  3. ini 文件操作记要(1): 使用 TIniFile

    ini 文件操作记要(1): 使用 TIniFile unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Class ...

  4. winform INI文件操作辅助类

    using System;using System.Runtime.InteropServices;using System.Text; namespace connectCMCC.Utils{ // ...

  5. Ini文件操作类

    /// <summary> /// Ini文件操作类 /// </summary> public class Ini { // 声明INI文件的写操作函数 WritePriva ...

  6. LabVIEW之生产者/消费者模式--队列操作

    LabVIEW之生产者/消费者模式--队列操作 彭会锋 本文章主要是对学习LabVIEW之生产者/消费者模式的学习笔记,其中涉及到同步控制技术-队列.事件.状态机.生产者-消费者模式,这几种技术在在本 ...

  7. python基础——15(加密、excel操作、ini文件操作、xml操作模块及数据格式分类)

    一.加密模块 1.有解密的加密方式(base64) #base64加密 import base64 str_encrypt = input("输入要加密的字符串:\n") base ...

  8. C# ini配置文件操作类

    /// <summary> /// INI文件操作类 /// </summary> public class IniFileHelper { /// <summary&g ...

  9. C# ini文件操作【源码下载】

    介绍C#如何对ini文件进行读写操作,C#可以通过调用[kernel32.dll]文件中的 WritePrivateProfileString()和GetPrivateProfileString()函 ...

随机推荐

  1. Webshell清除-解决驱动级文件隐藏挂马

    Webshell清除-解决驱动级文件隐藏挂马

  2. JavaSctipt语句for循环的思考

    一.语法 for (语句 1; 语句 2; 语句 3) { 被执行的代码块; } 语句 1: 在循环(代码块)开始前执行, 可选. 语句 2: 定义运行循环(代码块)的条件, 可选, 如果省略了语句 ...

  3. element-ui中下拉菜单中的@click事件不会触发的问题

    只需要将@click=“fun()”改为@click.native=“fun()”,即可监听下拉菜单的点击事件. 如图所示: 嗯,就酱~

  4. django实现密码加密的注册(数据对象插入)-结合forms表单实现表单验证

    forms表单 #_*_coding:utf-8_*_ from django import forms class regis(forms.Form): username = forms.CharF ...

  5. 前端框架之jQuery(二)----轮播图,放大镜

    事件 页面载入   ready(fn)  //当DOM载入就绪可以查询及操纵时绑定一个要执行的函数.   $(document).ready(function(){}) -----------> ...

  6. SQL语句中的Having子句与where子句

    一.介绍 聚合函数如SUM, COUNT, MAX, AVG等.这些函数和其它函数的根本区别就是它们一般作用在多条记录上.而通过使用GROUP BY 子句,可以让SUM 和 COUNT 这些函数对属于 ...

  7. centos7 Mysql5.6 升级Mysql5.7

    1 2. 卸载Mysql5.6 ,一共有三个包 要卸载: (1)先卸载mysql-server包 : 执行命令  yum remove mysql mysql-server (2)再卸载mysql-c ...

  8. PAT 天梯赛 L1-043. 阅览室 【STL】

    题目链接 https://www.patest.cn/contests/gplt/L1-043 思路 将每一次 借出和归还 都用 MAP 标记 如果归还的时候 已经被标记过了 那么 ANS ++ 并且 ...

  9. 转:ADO,OLEDB,ODBC,DAO的区别

    ODBC(Open Database Connectivity,开放数据库互连) 1992年,微软公司开放服务结构(WOSA,Windows Open Services Architecture)中有 ...

  10. 07_Warning $HADOOP_HOME is deprecated.去除办法

    Warning $HADOOP_HOME is deprecated.去除办法 警告的出现: 解决方案: 第一种: 去除[/etc/profile]文件中[export HADOOP_HOME=/op ...