Tag: string

应用程序设置中的StringCollection不会被存储

我想使用StringCollection作为应用程序设置,但是在阅读它不是问题时,我发现没有存储设置。 如何使其工作? 任何解决方法? 这有什么问题? 我正在使用的代码: private static void AddToRecentProfiles(string path) { if (SpellCaster3.Properties.Settings.Default.RecentProfiles == null) SpellCaster3.Properties.Settings.Default.RecentProfiles = new StringCollection(); int index = SpellCaster3.Properties.Settings.Default.RecentProfiles.IndexOf(path); if (index >= 0) SpellCaster3.Properties.Settings.Default.RecentProfiles.Swap(index, 0); else SpellCaster3.Properties.Settings.Default.RecentProfiles.Insert(0, path); if (SpellCaster3.Properties.Settings.Default.RecentProfiles.Count > SpellCaster3.Properties.Settings.Default.MaxRecentProfiles) SpellCaster3.Properties.Settings.Default.RecentProfiles.RemoveAt(SpellCaster3.Properties.Settings.Default.RecentProfiles.Count – 1); SpellCaster3.Properties.Settings.Default.Save(); OnRecentProfilesChanged(SpellCaster3.Properties.Settings.Default.RecentProfiles, EventArgs.Empty); }

为什么string.Empty比“”更推荐?

为什么string.Empty比””更推荐? 是因为当编译器解析代码并且”来了,编译器将准备好读取字符串?但是在string.Empty中编译器甚至不准备读取字符串?

C#3.0从字符串中删除字符

我有一个字符串,该怎么做 删除除英文字母以外的所有字符(a..z) 用一个空格替换所有空格序列 你会怎么用C#3.0做到这一点?

为什么string是引用类型,但行为与其他引用类型不同?

我们知道字符串是引用类型,所以我们有 string s=”God is great!”; 但是在同一个音符上,如果我声明类说Employee是一个引用类型,那么为什么下面的代码不起作用呢? Employee e = “Saurabh”; 2-我们如何确定类型是引用类型还是值类型?

如何从字符串中删除多个有问题的字符?

这是我的工作代码: string Input; string Output; Input = data; Output = Input.Replace(@”)”, “”); 在这里,我只是从我的字符串中删除括号“)”,如果它存在的话。 现在我如何扩展像“)”这样的违规字符列表,以包括“(”和“ – ”? 我意识到我可以写两个类似于输出的语句,但我想知道是否有更好的方法……

如何将字符串转换为颜色? 对于Windows Phone c#

我有一个用户控件,我已经将一个字符串绑定到xaml路径。 这使我可以选择“黑色”“蓝色”等颜色,并使用六角数作为字符串来选择颜色。 但是我无法在C#代码中使用相同的字符串。 以下示例中显示了以下内容: SolidColorBrush blackBrush = new SolidColorBrush(); SolidColorBrush mySolidColorBrush = new SolidColorBrush(); mySolidColorBrush.Color = shieldGearModelRec.Gear.Color; 所以最后一个字符串shieldGearModelRec.Gear.Color是我在XAML中用作绑定的。 它可以将颜色名称或六角形描述转换为颜色。 但是如何在后面的代码中执行此操作,即在c#中? 我的搜索在C#中找到了将字符串转换为Color等内容,但这在Windows手机中无法实现。 反正有没有完成这个? 一个主意 我是否需要创建一个读取字符串的转换器,查找#以确定它是否为hexa或颜色名称,然后使用hexa转换器查找rgb,以及名称的开关? 这似乎不是最聪明的解决方案

CRLF在C#中解析蓝调

我有以下代码: string myTest = “Line1Test” + Environment.NewLine + “Line2Test” + Environment.NewLine + “Line3Test” + Environment.NewLine; string[] parseStr = myTest.Split(Environment.NewLine.ToCharArray()); 我得到的是新数组中每隔一行的数据。 我认为这是因为分割线分为换行和回车,但我怎样才能每行得到一个元素?

为什么结构中的引用类型的行为类似于值类型?

我是C#编程的初学者。 我现在正在研究strings , structs , value types和reference types 。 作为此处和此处接受的答案, strings是引用类型,其指针存储在堆栈上,而它们的实际内容存储在堆上。 此外,如此处所声明的, structs是值类型。 现在我尝试使用一个小例子练习structs和strings : struct Person { public string name; } class Program { static void Main(string[] args) { Person person_1 = new Person(); person_1.name = “Person 1”; Person person_2 = person_1; person_2.name = “Person 2”; Console.WriteLine(person_1.name); Console.WriteLine(person_2.name); } } 上面的代码片段输出 Person 1 Person […]

从文本文件中删除某个字符串的最后一个实例,而不更改该字符串的其他实例

我有一个C#程序,我使用很多RegEx.Replace替换文本文件中的文本。 这是我的问题。 在我的文本文件中,我有一个代码,如“M6T1”。 此代码列在文本文件的许多位置。 但是,我只想从文本文件的底部(最后一个实例)中删除它。 文本文件底部总会有一个“M6T1”,但并不总是最后一行。 它可能是从底部开始的第3行,从底部开始的第5行等。 我只想摆脱“M6T1”的最后一个例子,所以RegEx.Replace在这里不起作用。 我不想干扰文本文件中其他位置的其他“M6T1”。 有人可以帮我解决这个问题吗? 谢谢

C#+运算符调用string.concat函数?

可能重复: C#是否优化了字符串文字的串联? 我刚刚发现我们写了这样一行: string s = “string”; s = s + s; // this translates to s = string.concat(“string”, “string”); 但是我通过reflection器打开了字符串类,我没看到这个+运算符在哪里重载? 我可以看到==和!=超载。 [TargetedPatchingOptOut(“Performance critical to inline across NGen image boundaries”)] public static bool operator ==(string a, string b) { return string.Equals(a, b); } [TargetedPatchingOptOut(“Performance critical to inline across NGen image boundaries”)] public static bool operator […]