Help us understand the problem. What is going on with this article?

めも

■セクション削除
WritePrivateProfileString("section", NULL, NULL, "Test.ini");

■キー値削除
WritePrivateProfileString("section", "key", NULL, ".\TestIni.ini");

■UniCodeによるiniファイルの読み書き
[DllImport("Kernel32.dll", CharSet=CharSet.Unicode, EntryPoint="GetPrivateProfileStringW")]
public static string GetIniStringW(string section, string key, string defaultText, string fileName)
{
StringBuilder sb = new StringBuilder(300);
uint ret = GetPrivateProfileStringW(section, key, defaultText, sb, 300U, fileName);
return sb.ToString();
}

[DllImport("kernel32.dll", EntryPoint = "WritePrivateProfileStringW", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool WritePrivateProfileString(
string lpAppName,
string lpKeyName,
string lpString,
string lpFileName
);

■テキストファイルをリストに読み込む

string line = "";
ArrayList al = new ArrayList();

using (StreamReader sr = new StreamReader(
    "readme.txt", Encoding.GetEncoding(utf16.EncodingName))) {

  while ((line = sr.ReadLine()) != null) {
    al.Add(line);

■テキストファイルへの書き込み
(書き加えるときは、System.IOのAppendを使用)
var fileName = @"c:\test.txt";
var encoding = System.Text.Encoding.GetEncoding("SHIFT_JIS");

using (var writer = new System.IO.StreamWriter(fileName, false, encoding))
{
for (int i = 0; i < 10; ++i)
{
var record = string.Format("{0}", i);
writer.WriteLine(record);
}
}

//先頭文字の取得
string s = "あいうえお";
//先頭から2文字を取得する。先頭の文字のインデックスは0。
string s1 = s.Substring(0, 2);
//1文字目の文字を取得する
char c1 = str[0];

//Unicodeテキストファイルの書き出し
StreamWriter sw = new StreamWriter(@"D:\test1.txt", false, new UTF16Encoding(true));
sw.WriteLine("東京都新宿区");
sw.Close();

//文字コード(UniCode)
var utf16 = System.Text.Encoding.Unicode;

//ファイルの末尾にTextBox1の内容を書き加える
System.IO.File.AppendAllText(filePath, TextBox1.Text, utf16.EncodingName);

//"C:\test\1.txt"をUniCodeとして開く
System.IO.StreamReader sr = new System.IO.StreamReader(
@"C:\test\1.txt",
utf16.EncodingName);
//内容をすべて読み込む
string s = sr.ReadToEnd();
//閉じる
sr.Close();

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away