0
Como contar Registros de um Aqruivo.ini e usa-las em loop
for (int i = 0; i < 15; i++)
{
Exemplo: no [bot] tenho 5 elementos cadastrados ! ao invez de ser 15
adicionado manualmente ao for eu usaria uma variavel no local -> que
daria o valor de 5 lidos automaticamente.
File Settings.ini
[bot]
b00=Debian
b01=Mineos
b02=Utorrent
b03=Debian Apache Web Server
b04=Debian Mysql Web Server
b05=Ez Monitor
[web]
h00=https://debian:10100/
h01=https://debian:8443/
h02=https://debian:8080/gui/
h03=http://ccstudio.zapto.org/
h04=http://debian/phpmyadmin/
h05=http://debian/app/cc/linux/eZ/
h06=http://debian:19999
My Used Class
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
/ / Change this to match your program's normal namespace
namespace MyProg
{
class IniFile // revision 11
{
string Path;
string EXE = Assembly.GetExecutingAssembly().GetName().Name;
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath);
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath);
public IniFile(string IniPath = null)
{
Path = new FileInfo(IniPath ?? EXE + ".ini").FullName.ToString();
}
public string Read(string Key, string Section = null)
{
var RetVal = new StringBuilder(255);
GetPrivateProfileString(Section ?? EXE, Key, "", RetVal, 255, Path);
return RetVal.ToString();
}
public void Write(string Key, string Value, string Section = null)
{
WritePrivateProfileString(Section ?? EXE, Key, Value, Path);
}
public void DeleteKey(string Key, string Section = null)
{
Write(Key, null, Section ?? EXE);
}
public void DeleteSection(string Section = null)
{
Write(null, null, Section ?? EXE);
}
public bool KeyExists(string Key, string Section = null)
{
return Read(Key, Section).Length > 0;
}
}
}
What’s the problem? What exactly are you trying to do?
– CypherPotato
and that I don’t know how to do that I already searched and I don’t know how to count the names of an ini file or the addresses and put them separately in a loop for (int i = 0; i < 15; i++) in 15 for example that’s the amount I have of names in aqruivo and leave it automatic.
– carlos coelho
You are trying to count how many elements there are in a file . ini, correct?
– CypherPotato
yes I am tempted but I can’t imagine how ! already search only found to read and write but to read quantity of records .. nothing
– carlos coelho