相关疑难解决方法(0)

如何从路径和文件名中删除非法字符?

我需要一种强大而简单的方法来从简单的字符串中删除非法路径和文件字符.我使用了下面的代码,但它似乎没有做任何事情,我错过了什么?

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string illegal = "\"M<>\"\\a/ry/ h**ad:>> a\\/:*?\"<>| li*tt|le|| la\"mb.?";

            illegal = illegal.Trim(Path.GetInvalidFileNameChars());
            illegal = illegal.Trim(Path.GetInvalidPathChars());

            Console.WriteLine(illegal);
            Console.ReadLine();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# string directory path

423
推荐指数
17
解决办法
41万
查看次数

检查并删除字符串中的任何字符

我想知道指定一个字符数组的最佳方法是什么,

{
}
[
]
Run Code Online (Sandbox Code Playgroud)

然后检查字符串是否存在,如果它们在那里,则完全删除它们.

        if (compiler.Parser.GetErrors().Count == 0)
        {
            AstNode root = compiler.Parse(phrase.ToLower());
            if (compiler.Parser.GetErrors().Count == 0)
            {
                try
                {
                    fTextSearch = SearchGrammar.ConvertQuery(root, SearchGrammar.TermType.Inflectional);
                }
                catch
                {
                    fTextSearch = phrase;
                }
            }
            else
            {
                fTextSearch = phrase;
            }
        }
        else
        {
            fTextSearch = phrase;
        }

        string[] brackets = brackets = new string[]
        {
            "{",
            "}",
            "[",
            "]"
        };

        string[] errorChars = errorChars = new string[]
        {
            "'",
            "&"
        };

        StringBuilder sb = new StringBuilder();

        string[] splitString = fTextSearch.Split(errorChars, …
Run Code Online (Sandbox Code Playgroud)

c#

0
推荐指数
2
解决办法
1075
查看次数

标签 统计

c# ×2

directory ×1

path ×1

string ×1