Tag: C#的

删除string中的空格最快的方法

我试图从数据库表中的string中获取由“,”分隔的多个电子邮件地址,但它也返回给我的空格,我想快速删除空白。 下面的代码确实删除了空格,但是当我尝试在像30000这样的string中获取大量电子邮件地址时,它也变得很慢,然后尝试删除它们之间的空格。 需要四到五分钟时间去除这些空间。 Regex Spaces = new Regex(@"\s+", RegexOptions.Compiled); txtEmailID.Text = MultipleSpaces.Replace(emailaddress),""); 任何人都可以告诉我,即使大量的电子邮件地址,我怎样才能删除一秒钟内的空白?

关于将const引用绑定到临时对象的子对象

与代码一样 #include <iostream> struct P { int x; P(int x) : x(x) {} ~P() { std::cout << "~P()\n"; } }; int main() { auto const& x = P{10}.x; std::cout << "extract\n"; } 海湾合作委员会打印~P() extract ,表明临时的生存期不被引用扩展。 相反,Clang(IMO正确地)将临时的生命周期延长到参考x的生命周期,因此在main的输出之后将调用析构函数。 请注意,GCC突然显示了Clang的行为,如果我们,而不是int ,使用一些类types(例如string )。 这是GCC中的错误还是标准允许的?

活动目录COMexception – 发生操作错误(0x80072020)

我得到一个间歇性COMexception“ 操作错误发生(0x80072020) ”(如下所示)当我尝试使用方法GroupPrincipal.FindByIdentity查询Active Directory 这是我的代码: PrincipalContext ctx = new PrincipalContext(ContextType.Domain, Environment.UserDomainName); GroupPrincipal groupPrincipal = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, "Group to find"); 我收到exception: Inner Exception: System.Runtime.InteropServices.COMException (0x80072020): An operations error occurred. at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_AdsObject() at System.DirectoryServices.PropertyValueCollection.PopulateList() at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName) at System.DirectoryServices.PropertyCollection.get_Item(String propertyName) at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer() at System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() at System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext […]

如何定义一个包含自身指针的typedef结构?

我在C写一个LinkedList,下面的代码表示我的节点定义。 typedef struct { int value; struct Node* next; struct Node* prev; } Node; 我明白(或者认为我是) struct Node不同于typedef struct Node 。 授予我的代码编译和运行,因为它应该,但是,当分配next和prev (警告:从不兼容的指针types赋值)时,我得到了很多警告。 我猜测这与我如何在Node结构中定义它们有关。 我在这里上传了完整的源代码 所以,如果确实是这个问题,我应该如何在typedef struct Node定义next和prev ? 我担心这可能是一个转发,但不能find我正在寻找的东西。 谢谢。

C#int,Int32和枚举

如果int与Int32同义,为什么呢 enum MyEnum : Int32 { Value = 1 } …不编译? 在哪里 enum MyEnum : int { Value = 1 } 会,即使鼠标hover在整数字将显示结构System.Int32?

我怎么知道内联函数是否在被调用的地方被replace了?

我知道内联函数要么被replace,要么被调用,或者像一个正常的函数一样。 但是,我怎么知道内联函数实际上是否在被调用的地方被replace,因为内联函数是在编译时处理的决定?

内存效率和String.Replace .NET Framework的性能

string str1 = "12345ABC…\\…ABC100000"; // Hypothetically huge string of 100000 + Unicode Chars str1 = str1.Replace("1", string.Empty); str1 = str1.Replace("22", string.Empty); str1 = str1.Replace("656", string.Empty); str1 = str1.Replace("77ABC", string.Empty); // … this replace anti-pattern might happen with upto 50 consecutive lines of code. str1 = str1.Replace("ABCDEFGHIJD", string.Empty); 我inheritance了一些与上面的代码片段相同的代码。 它需要一个巨大的string,并从大string中replace(删除)常量较小的string。 我相信这是一个内存密集型的过程,因为每个replace内存都会分配新的大型不可变string,以便通过GC等待死亡。 1.什么是取代这些价值观的最快方式,忽略了记忆的顾虑? 2.达到相同结果的最有效的内存方式是什么? 我希望这些答案是一样的! 适合这些目标之间的实用解决scheme也是值得赞赏的。 假设: […]

在C或C ++中以编程方式删除非空目录

如何删除C或C ++中的非空目录? 有没有什么function? rmdir只删除空目录。 请提供一种不使用任何外部库的方式。 另外告诉我如何删除C或C ++文件?

C#中的成对迭代或滑动窗口枚举器

如果我有一个像IEnumerable: string[] items = new string[] { "a", "b", "c", "d" }; 我想循环所有的连续项目对(2号滑动窗口)。 这将是 ("a","b"), ("b", "c"), ("c", "d") 我的解决办法是这样的 public static IEnumerable<Pair<T, T>> Pairs(IEnumerable<T> enumerable) { IEnumerator<T> e = enumerable.GetEnumerator(); e.MoveNext(); T current = e.Current; while ( e.MoveNext() ) { T next = e.Current; yield return new Pair<T, T>(current, next); current = next; } […]

检查Unix中是否存在目录(系统调用)

我无法在网上find解决我的问题的方法。 我想在Unix中调用一个函数,传递一个目录的path,并知道它是否存在。 如果一个目录不存在, opendir()返回一个错误,但是我的目标不是实际打开,检查错误,closures它,如果没有错误,而只是检查一个文件是否是一个目录。 请问有什么方便的方法吗?