| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

C Sharp

提供: MyMemoWiki
2020年9月9日 (水) 03:03時点におけるPiroto (トーク | 投稿記録)による版 (→‎Tips)
ナビゲーションに移動 検索に移動

| Visual Studio | VC++ | Visual Studio Code |

C#

言語まとめ C#

概要

Win32 API DLL の利用

Windows Forms

C# Windows Forms Tips

C# 設定情報を保存する

データベース

SQL Server Compact

制御

書式

Sleep

画面・コントロール

グラフ

タスクトレイ

リソース

文字列

デバッグ

Visual Studio

Visual Studio 2010 Express C#

コーディング規約

Tips

Subversion プラグイン

文字コード変換

正規表現による置換

var output = System.Text.RegularExpressions.Regex.Replace(input, @"^[ ]", "");

string を stream に変換

 return new MemoryStream(Encoding.UTF8.GetBytes(value ?? ""));

ディレクトリを再帰的に表

class Program
{
    static void Main(string[] args)
    {
        var me = new Program();
        me.Parse(args[0], 0);
    }

    private void Parse(string path, int depth)
    {
        var indent = new string(' ', depth * 2);
        foreach (var entry in Directory.EnumerateFileSystemEntries(path))
        {
            var attr = File.GetAttributes(entry);
            if (attr.HasFlag(FileAttributes.Directory))
            {
                Console.WriteLine($"{indent}{Path.GetDirectoryName(entry)}\\");
                this.Parse(entry, depth + 1);
            }
            Console.WriteLine($"{indent}{Path.GetFileName(entry)}");
        }
    }
}

SHIFT-JIS 文字列から、SO SI を除去

var encShiftJis = Encoding.GetEncoding("shift_jis");
int lino = 1;
using (var reader = new StreamReader(path, encShiftJis))
{
    string line = null;
    while ((line = reader.ReadLine())!=null)
    {
        byte[] bytes = encShiftJis.GetBytes(line);
        for(int i=0;i<bytes.Length; i++)
        {
            // bytes = bytes.Where(b => (b != 0x20 /*space*/ && b != 0x61 /*'a'*/)).ToArray();
            bytes = bytes.Where(b => (b != 0x0E /*SO*/ || b != 0x0F /*SI*/)).ToArray();
        }
        line = encShiftJis.GetString(bytes);
        Console.WriteLine($"{indent}{lino++:D4}:{line}");
    }
}