C#

/// <summary>
/// 使用禁止文字の置換
/// </summary>
/// <param name="strData"></param>
/// <returns></returns>
private static string ReplaceInvalidChar(string strData)
{
    string strResult = strData;

    foreach (char invalidChar in Path.GetInvalidFileNameChars())
    {
        while (strResult.IndexOf(invalidChar) >= 0)
        {
            strResult = strResult.Remove(strResult.IndexOf(invalidChar), 1);
        }
    }

    List<string> arrayReplaceChar = new List<string> { "*", "/", "&", """, "\", "
", "
", "	", "<", ">", "[", "]", "{", "}", "|", ":", ";", "?", "!", ",", ".", "=", "~", "$", "%" };

    foreach (string strReplaceChar in arrayReplaceChar)
    {
        strResult = strResult.Replace(strReplaceChar, "");
        strResult = strResult.Replace(Strings.StrConv(strReplaceChar, VbStrConv.Wide), "");
    }

    strResult = strResult.Trim(' ');

    return strResult;
}