【LABVIEW到C#】1》ini的操作

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的操作的更多相关文章
- LabVIEW之生产者/消费者模式--队列操作 彭会锋
LabVIEW之生产者/消费者模式--队列操作 彭会锋 本文章主要是对学习LabVIEW之生产者/消费者模式的学习笔记,其中涉及到同步控制技术-队列.事件.状态机.生产者-消费者模式,这几种技术在在本 ...
- ini文件操作
Config.ini 文件操作 [SYS] sysname=hy company=hyhy tel=2 using System; using System.Collections.Generic; ...
- ini 文件操作记要(1): 使用 TIniFile
ini 文件操作记要(1): 使用 TIniFile unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Class ...
- winform INI文件操作辅助类
using System;using System.Runtime.InteropServices;using System.Text; namespace connectCMCC.Utils{ // ...
- Ini文件操作类
/// <summary> /// Ini文件操作类 /// </summary> public class Ini { // 声明INI文件的写操作函数 WritePriva ...
- LabVIEW之生产者/消费者模式--队列操作
LabVIEW之生产者/消费者模式--队列操作 彭会锋 本文章主要是对学习LabVIEW之生产者/消费者模式的学习笔记,其中涉及到同步控制技术-队列.事件.状态机.生产者-消费者模式,这几种技术在在本 ...
- python基础——15(加密、excel操作、ini文件操作、xml操作模块及数据格式分类)
一.加密模块 1.有解密的加密方式(base64) #base64加密 import base64 str_encrypt = input("输入要加密的字符串:\n") base ...
- C# ini配置文件操作类
/// <summary> /// INI文件操作类 /// </summary> public class IniFileHelper { /// <summary&g ...
- C# ini文件操作【源码下载】
介绍C#如何对ini文件进行读写操作,C#可以通过调用[kernel32.dll]文件中的 WritePrivateProfileString()和GetPrivateProfileString()函 ...
随机推荐
- 学习即语言的学习 “表示” “presentation”
w 龚升
- VS中没有为此解决方案配置选中要生成的项目
菜单->生成->配置管理器->给要生成的项目打钩
- JavaScript中label与break配合使用
语法 label: statement 说明 label语句可以在代码中添加标签,以便将来使用.定义的标签可以在将来由break或continue语句引用.加标签的语句一般都要与for语句等循环语句配 ...
- 【转】Power System 中基于 VIOS 的虚拟以太网实现
基于 VIOS 的虚拟以太网适配器的工作原理和配置实现 本文对 Power 系统中基于 VIOS 的虚拟以太网适配器(Virtual Ethernet Adapter)的工作原理.基本配置选项和配置步 ...
- 介绍一下except的用法和作用?
Python的except用来捕获所有异常,因为Python里面的每次错误都会抛出一个异常,所以每个程序的错误都被当作一个运行时错误.
- python生成器&迭代器
列表生成式 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 里每个值都加一 普通做法 a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]for index,i in e ...
- Android系统移植与调试之------->如何修改Android手机NFC模块,使黑屏时候能够使用NFC
我们都知道在不修改源代码的情况下,只能是解锁之后才能使用NFC功能.而在锁屏和黑屏2个状态下是没办法用NFC的,但是最近有个客户要求手机在黑屏状态下能够使用NFC,因此我们需要去修改Android源代 ...
- java定时器的使用(Timer)(转发:https://blog.csdn.net/ecjtuxuan/article/details/2093757)
1.在应用开发中,经常需要一些周期性的操作,比如每5分钟执行某一操作等. 对于这样的操作最方便.高效的实现方式就是使用java.util.Timer工具类. private java.util.Tim ...
- Python之正则表达式与常用模块(Day19)
一.正则表达式:匹配字符串的一种规则 正则表达式的在线测试工具: http://tool.chinaz.com/regex/ 字符组: 正则 待匹配字符 匹配结果 说明 [0123456789] 8 ...
- django-admin 修改admin自带模版
还不知道怎么指定修改每个页面,我就把把所有修改写在一个页面,通过url进行判断是否是是否显示修改内容,修改的是change_form.html ,在admin里面可以找到 {% block objec ...