第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

我想,既然有下面的兩個(gè)函數(shù),也一定有我所說的這種函數(shù)?

我想,既然有下面的兩個(gè)函數(shù),也一定有我所說的這種函數(shù)?

偶然的你 2023-04-22 18:14:19
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, _ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As LongPublic Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, _ByVal lpFileName As String) As LongPublic MainIniFile As String我用這套函數(shù)讀寫INI文件,可是怎么刪除一個(gè)項(xiàng),或者一個(gè)值?挨個(gè)將值設(shè)為空不好。那樣太麻煩。最好可以一次刪除一個(gè)項(xiàng)以及其下的所有值(例如[Settings]以及它下面的所有值)。還得能單獨(dú)刪除一個(gè)值(例如aaa=1這一行)就像DeleteSetting()函數(shù)一樣,只不過是針對(duì)ini文件而已。
查看完整描述

2 回答

?
拉丁的傳說

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊

代碼:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace IniFiles
{
public abstract class CustomIniFile
{
public CustomIniFile(string AFileName) 
{
FFileName = AFileName;
}
private string FFileName;
public string FileName
{
get { return FFileName; }
}
public virtual bool SectionExists(string Section)
{
List<string> vStrings = new List<string>();
ReadSections(vStrings);
return vStrings.Contains(Section);
}
public virtual bool ValueExists(string Section, string Ident)
{
List<string> vStrings = new List<string>();
ReadSection(Section, vStrings);
return vStrings.Contains(Ident);
}
public abstract string ReadString(string Section, string Ident, string Default);
public abstract bool WriteString(string Section, string Ident, string Value);
public abstract bool ReadSectionValues(string Section, List<string> Strings);
public abstract bool ReadSection(string Section, List<string> Strings);
public abstract bool ReadSections(List<string> Strings);
public abstract bool EraseSection(string Section);
public abstract bool DeleteKey(string Section, string Ident);
public abstract bool UpdateFile();
}

/// <summary>
/// 存儲(chǔ)本地INI文件的類。
/// </summary>
public class IniFile : CustomIniFile
{
[DllImport("kernel32")]
private static extern uint GetPrivateProfileString(
string lpAppName, // points to section name 
string lpKeyName, // points to key name 
string lpDefault, // points to default string 
byte[] lpReturnedString, // points to destination buffer 
uint nSize, // size of destination buffer 
string lpFileName // points to initialization filename 
);

[DllImport("kernel32")]
private static extern bool WritePrivateProfileString(
string lpAppName, // pointer to section name 
string lpKeyName, // pointer to key name 
string lpString, // pointer to string to add 
string lpFileName // pointer to initialization filename 
);

/// <summary>
/// 構(gòu)造IniFile實(shí)例。
/// <param name="AFileName">指定文件名</param>
/// </summary>
public IniFile(string AFileName)
: base(AFileName)
{
}

/// <summary>
/// 析夠IniFile實(shí)例。
/// </summary>
~IniFile()
{
UpdateFile();
}

/// <summary>
/// 讀取字符串值。
/// <param name="Ident">指定變量標(biāo)識(shí)。</param>
/// <param name="Section">指定所在區(qū)域。</param>
/// <param name="Default">指定默認(rèn)值。</param>
/// <returns>返回讀取的字符串。如果讀取失敗則返回該值。</returns>
/// </summary>
public override string ReadString(string Section, string Ident, string Default)
{
byte[] vBuffer = new byte[2048];
uint vCount = GetPrivateProfileString(Section,
Ident, Default, vBuffer, (uint)vBuffer.Length, FileName);
return Encoding.Default.GetString(vBuffer, 0, (int)vCount);
}
/// <summary>
/// 寫入字符串值。
/// </summary>
/// <param name="Section">指定所在區(qū)域。</param>
/// <param name="Ident">指定變量標(biāo)識(shí)。</param>
/// <param name="Value">所要寫入的變量值。</param>
/// <returns>返回寫入是否成功。</returns>
public override bool WriteString(string Section, string Ident, string Value)
{
return WritePrivateProfileString(Section, Ident, Value, FileName);
}

/// <summary>
/// 獲得區(qū)域的完整文本。(變量名=值格式)。
/// </summary>
/// <param name="Section">指定區(qū)域標(biāo)識(shí)。</param>
/// <param name="Strings">輸出處理結(jié)果。</param>
/// <returns>返回讀取是否成功。</returns>
public override bool ReadSectionValues(string Section, List<string> Strings)
{
List<string> vIdentList = new List<string>();
if (!ReadSection(Section, vIdentList)) return false;
foreach (string vIdent in vIdentList)
Strings.Add(string.Format("{0}={1}", vIdent, ReadString(Section, vIdent, "")));
return true;
}

/// <summary>
/// 讀取區(qū)域變量名列表。
/// </summary>
/// <param name="Section">指定區(qū)域名。</param>
/// <param name="Strings">指定輸出列表。</param>
/// <returns>返回獲取是否成功。</returns>
public override bool ReadSection(string Section, List<string> Strings)
{
byte[] vBuffer = new byte[16384];
uint vLength = GetPrivateProfileString(Section, null, null, vBuffer,
(uint)vBuffer.Length, FileName);
int j = 0;
for (int i = 0; i < vLength; i++)
if (vBuffer[i] == 0)
{
Strings.Add(Encoding.Default.GetString(vBuffer, j, i - j));
j = i + 1;
}
return true;
}

/// <summary>
/// 讀取區(qū)域名列表。
/// </summary>
/// <param name="Strings">指定輸出列表。</param>
/// <returns></returns>
public override bool ReadSections(List<string> Strings)
{
byte[] vBuffer = new byte[16384];
uint vLength = GetPrivateProfileString(null, null, null, vBuffer, 
(uint)vBuffer.Length, FileName);
int j = 0;
for (int i = 0; i < vLength; i++)
if (vBuffer[i] == 0)
{
Strings.Add(Encoding.Default.GetString(vBuffer, j, i - j));
j = i + 1;
}
return true;
}

/// <summary>
/// 刪除指定區(qū)域。
/// </summary>
/// <param name="Section">指定區(qū)域名。</param>
/// <returns>返回刪除是否成功。</returns>
public override bool EraseSection(string Section)
{
return WritePrivateProfileString(Section, null, null, FileName);
}

/// <summary>
/// 刪除指定變量。
/// </summary>
/// <param name="Section">變量所在區(qū)域。</param>
/// <param name="Ident">變量標(biāo)識(shí)。</param>
/// <returns>返回刪除是否成功。</returns>
public override bool DeleteKey(string Section, string Ident)
{
return WritePrivateProfileString(Section, Ident, null, FileName);
}

/// <summary>
/// 更新文件。
/// </summary>
/// <returns>返回更新是否成功。</returns>
public override bool UpdateFile()
{
return WritePrivateProfileString(null, null, null, FileName);
}
}
}

EraseSection() // 刪除一個(gè)區(qū)塊
DeleteKey() // 刪除一個(gè)鍵值

查看完整回答
反對(duì) 回復(fù) 2023-04-25
?
弒天下

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊

刪除節(jié)點(diǎn)及節(jié)點(diǎn)中所有值
Public Sub EraseSection(ByVal Section As String, ByVal FileName As String)
WritePrivateProfileString Section, Null, Null, FileName
End Sub 

刪除指定值Ident
WritePrivateProfileString(Section, Ident, null, FileName);

查看完整回答
反對(duì) 回復(fù) 2023-04-25
  • 2 回答
  • 0 關(guān)注
  • 224 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)