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. Server Objects Extension(SOE)开发(一)

    1.SOE相关 1.1 什么是SOE SOE(Server对象扩展:Server Object Extenstion),其通过采用ArcObjects的相关的接口.类库对ArcGIS Server的基 ...

  2. [String ] StringBuffer VS StringBuilder

    StringBuilder的性能高于StringBuffer,因为StringBuffer是线程安全的. 首先说明一下,一般情况下,字符串相加默认是StringBuilder,但是当数量大于100,或 ...

  3. 剑指offer 面试40题

    面试40题: 题目:最小的k个数 题:输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,. 解题代码一: # -*- coding ...

  4. Android 结束进程的方法forceStopPackage

    ActivityManager sd = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); Method method = Clas ...

  5. jQuery:自学笔记(4)——事件与事件对象

    jQuery:自学笔记(4)——事件与事件对象 jQuery中的事件 什么是事件 所谓事件,就是被对象识别的操作,即操作对象队环境变化的感知和反应,例如单击按钮或者敲击键盘上的按键. 所谓事件流,是指 ...

  6. web中的编码问题

    response返回有两种,一种是字节流outputstream,一种是字符流printwrite. 先说字节流,要输出“中国",给输出流的必须是转换为utf-8的“中国”,还要告诉浏览器, ...

  7. 虚构 css 父级选择器

    能 CSS 解决的绝不用 JS,这句话又一次故作装逼地说出来还是挺爽的... 比如下拉列表,能用 CSS 的 :focus 就不用 JS 的 .on("focus blur") 能 ...

  8. 在freescale mx6q平台上添加spi资源

    1:配置管脚为SPI功能 在board-mx6q_sabresd.h的最后添加,复制被重定义 (以添加SPI2为例) <span style="font-size:18px;" ...

  9. 跨平台移动开发_PhoneGap API 事件类型

    PhoneGap API Events backbuttondevicereadymenubuttonpauseresumeonlineofflinebatterycriticalbatterylow ...

  10. awk的逻辑运算符

    运算符 描述 赋值运算符 = += -= *= /= %= ^= **= 赋值语句 逻辑运算符 || 逻辑或 && 逻辑与 正则运算符 ~ ~! 匹配正则表达式和不匹配正则表达式 关系 ...