stringbuilder

How do I remove diacritics (accents) from a string in .NET?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to convert some strings that are in French Canadian and basically, I'd like to be able to take out the French accent marks in the letters while keeping the letter. (E.g. convert é to e , so would become creme brulee ) What is the best method for achieving this? 回答1: I've not used this method, but Michael Kaplan describes a method for doing so in his blog post (with a confusing title) that talks about stripping diacritics: Stripping is an interesting job (aka On the meaning of meaningless, aka All Mn characters are non-spacing, but

What is the most efficient algorithm for reversing a String in Java?

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What is the most efficient way to reverse a string in Java? Should I use some sort of xor operator? The easy way would be to put all the chars in a stack and put them back into a string again but I doubt that's a very efficient way to do it. And please do not tell me to use some built in function in Java. I am interested in learning how to do it not to use an efficient function but not knowing why it's efficient or how it's built up. 回答1: You say you want to know the most efficient way and you don't want to know some standard built-in way of

Clearing a string buffer/builder after loop

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do you clear the string buffer in Java after a loop so the next iteration uses a clear string buffer? 回答1: One option is to use the delete method as follows: StringBuffer sb = new StringBuffer(); for (int n = 0; n Another option (bit cleaner) uses setLength(int len) : sb.setLength(0); See Javadoc for more info: 回答2: The easiest way to reuse the StringBuffer is to use the method setLength() public void setLength(int newLength) You may have the case like StringBuffer sb = new StringBuffer("HelloWorld"); // after many iterations and

Why is this not throwing a NullPointerException?

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Nead clarification for following code: StringBuilder sample = new StringBuilder (); StringBuilder referToSample = sample ; referToSample . append ( "B" ); System . out . println ( sample ); This will print B so that proves sample and referToSample objects refer to the same memory reference. StringBuilder sample = new StringBuilder (); StringBuilder referToSample = sample ; sample . append ( "A" ); referToSample . append ( "B" ); System . out . println ( referToSample ); This will print AB that also proves the same. StringBuilder

c# datatable to csv

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Could somebody please tell me why the following code is not working. The data is saved into the csv file, however the data is not separated. It all exists within the first cell of each row. StringBuilder sb = new StringBuilder(); foreach (DataColumn col in dt.Columns) { sb.Append(col.ColumnName + ','); } sb.Remove(sb.Length - 1, 1); sb.Append(Environment.NewLine); foreach (DataRow row in dt.Rows) { for (int i = 0; i Thanks. 回答1: The following shorter version opens fine in Excel, maybe your issue was the trailing comma .net = 3.5

java: use StringBuilder to insert at the beginning

那年仲夏 提交于 2019-12-03 01:46:53
问题 I could only do this with String, for example: String str=""; for(int i=0;i<100;i++){ str=i+str; } Is there a way to achieve this with StringBuilder? Thanks. 回答1: StringBuilder sb = new StringBuilder(); for(int i=0;i<100;i++){ sb.insert(0, Integer.toString(i)); } Warning: It defeats the purpose of StringBuilder , but it does what you asked. Better technique (although still not ideal): Reverse each string you want to insert. Append each string to a StringBuilder . Reverse the entire

Is there an easy way to concatenate several lines of text into a string without constantly appending a newline?

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: So I essentially need to do this: String text = "line1\n" ; text += "line2\n" ; text += "line3\n" ; useString ( text ); There is more involved, but that's the basic idea. Is there anything out there that might let me do something more along the lines of this though? DesiredStringThinger text = new DesiredStringThinger (); text . append ( "line1" ); text . append ( "line2" ); text . append ( "line3" ); useString ( text . toString () ); Obviously, it does not need to work exactly like that, but I think I get the basic point across.

When is it better to use String.Format vs string concatenation?

匿名 (未验证) 提交于 2019-12-03 01:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've got a small piece of code that is parsing an index value to determine a cell input into Excel. It's got me thinking... What's the difference between xlsSheet.Write("C" + rowIndex.ToString(), null, title); and xlsSheet.Write(string.Format("C{0}", rowIndex), null, title); Is one "better" than the other? And why? 回答1: Before C# 6 To be honest, I think the first version is simpler - although I'd simplify it to: xlsSheet.Write("C" + rowIndex, null, title); I suspect other answers may talk about the performance hit, but to be honest it'll be

How to get a list of installed software products?

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I get a list of software products which are installed on the system. My goal is to iterate through these, and get the installation path of a few of them. PSEUDOCODE ( combining multiple languages :) ) foreach InstalledSoftwareProduct if InstalledSoftwareProduct.DisplayName LIKE *Visual Studio* print InstalledSoftwareProduct.Path 回答1: You can use MSI api functions to enumerate all installed products. Below you will find sample code which does that. In my code I first enumerate all products, get the product name and if it contains the

Using LINQ to concatenate strings

匿名 (未验证) 提交于 2019-12-03 01:17:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What is the most efficient way to write the old-school: StringBuilder sb = new StringBuilder(); if (strings.Count > 0) { foreach (string s in strings) { sb.Append(s + ", "); } sb.Remove(sb.Length - 2, 2); } return sb.ToString(); ...in LINQ? 回答1: Use aggregate queries like this: string[] words = { "one", "two", "three" }; var res = words.Aggregate((current, next) => current + ", " + next); Console.WriteLine(res); This outputs: one, two, three An aggregate is a function that takes a collection of values and returns a scalar value. Examples