stringbuilder

Read all ini file values with GetPrivateProfileString

浪尽此生 提交于 2019-12-03 02:37:47
I need a way to read all sections/keys of ini file in a StringBuilder variable: [DllImport("kernel32.dll")] private static extern int GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName); ... private List<string> GetKeys(string iniFile, string category) { StringBuilder returnString = new StringBuilder(255); GetPrivateProfileString(category, null, null, returnString, 32768, iniFile); ... } In returnString is only the first key value! How it is possible to get all at once and write it to the StringBuilder and

MSI Interop using MSIEnumRelatedProducts and MSIGetProductInfo

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Whilst working with the MSI Interop API I have come across some unusual behaviour which is causing my application to crash. It is simple enough to 'handle' the problem but I would like to know more about 'why' this is happening. My first call to MSIEnumRelatedProducts returns an value of 0 and correctly sets my string buffer to a productcode. My understanding is that this would only happen if the given upgradecode (passed as a parm to the method) has a 'related family product' currently installed, otherwise it would return 259 ERROR_NO_MORE

How to show Windows Login Dialog?

匿名 (未验证) 提交于 2019-12-03 02:28:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How to display Windows Login dialog box whitin a windows WPF application? 回答1: Looks similar to Show Authentication dialog in C# for windows Vista/7 CredUIPromptForWindowsCredentials 回答2: I wrote a helper class for this. It shows the "XP Style" login dialog, not the one you're showing in your screenshot, but you'll be able to go on from there to show the "new" dialog, too: public static class UserHelper { [Flags] public enum CREDUI_FLAGS { INCORRECT_PASSWORD = 0x1, DO_NOT_PERSIST = 0x2, REQUEST_ADMINISTRATOR = 0x4, EXCLUDE_CERTIFICATES = 0x8

How can i remove none alphabet chars from a string[]? [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:26:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: How do I remove all non alphanumeric characters from a string except dash? 11 answers This is the code: StringBuilder sb = new StringBuilder(); Regex rgx = new Regex("[^a-zA-Z0-9 -]"); var words = Regex.Split(textBox1.Text, @"(?=(?<=[^\s])\s+\w)"); for (int i = 0; i < words.Length; i++) { words[i] = rgx.Replace(words[i], ""); } When im doing the Regex.Split() the words contain also strings with chars inside for exmaple: Daniel> or Hello: or \r\nNew or hello--------------------------- And i need to

Most efficient Dictionary&lt;K,V&gt;.ToString() with formatting?

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What's the most efficient way to convert a Dictionary to a formatted string. e.g.: My method: public string DictToString(Dictionary<string, string> items, string format){ format = String.IsNullOrEmpty(format) ? "{0}='{1}' " : format; string itemString = ""; foreach(var item in items){ itemString = itemString + String.Format(format,item.Key,item.Value); } return itemString; } Is there a better/more concise/more efficient way? Note: the Dictionary will have at most 10 items and I'm not committed to using it if another similar "key-value pair"

Partial function application in Java 8

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to partially apply some arguments to a legacy method using Java 8's newly introduced function objects. Here is the method in question: /** * Appends a {@code character} a couple of {@code times} to a {@code string}. * * @return the string with the appended characters as a StringBuilder */ private static StringBuilder appendChar(char character, int times, String string) { StringBuilder strBuilder = new StringBuilder(string); for (int i = 0; i < times; i++) { strBuilder.append(character); } return strBuilder; } 回答1: This achieves what I

C# 转json

北城以北 提交于 2019-12-03 02:19:07
#region MyRegion StringBuilder sb = new StringBuilder(); sb.Append("{"); foreach (System.Reflection.PropertyInfo p in model.GetType().GetProperties()) { var ss = p.Name; //属性名称 if (ss == "Role" || ss == "Department" || ss == "ApplySolver") { continue; } var s1 = p.GetValue(model);//属性值 sb.AppendFormat("\"{0}\":\"{1}\"", ss, s1); sb.Append(","); } sb.Remove(sb.Length - 1, 1); sb.Append("}"); desc = sb.ToString(); sb.Length = 0; #endregion 来源: https://www.cnblogs.com/enych/p/11771059.html

java面试题

大憨熊 提交于 2019-12-03 02:15:55
Java 基础 1. JDK 和 JRE 有什么区别? JDK:Java Development Kit 的简称,java 开发工具包,提供了 java 的开发环境和运行环境。 JRE:Java Runtime Environment 的简称,java 运行环境,为 java 的运行提供了所需环境。 具体来说 JDK 其实包含了 JRE,同时还包含了编译 java 源码的编译器 javac,还包含了很多 java 程序调试和分析的工具。简单来说:如果你需要运行 java 程序,只需安装 JRE 就可以了,如果你需要编写 java 程序,需要安装 JDK。 2. == 和 equals 的区别是什么? == 解读 对于基本类型和引用类型 == 的作用效果是不同的,如下所示: 基本类型:比较的是值是否相同; 引用类型:比较的是引用是否相同; 代码示例: String x = "string"; String y = "string"; String z = new String("string"); System.out.println(x==y); // true System.out.println(x==z); // false System.out.println(x.equals(y)); // true System.out.println(x.equals(z)); //

Android StringBuilder vs String Concatenation

孤人 提交于 2019-12-03 02:08:21
I was reading this documentation page, http://developer.android.com/reference/android/util/Log.html . The section here caught my eye: Tip: Don't forget that when you make a call like Log.v(TAG, "index=" + i); that when you're building the string to pass into Log.d, the compiler uses a StringBuilder and at least three allocations occur: the StringBuilder itself, the buffer, and the String object. Realistically, there is also another buffer allocation and copy, and even more pressure on the gc. That means that if your log message is filtered out, you might be doing significant work and incurring

String concatenation in Java - when to use +, StringBuilder and concat [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: This question already has an answer here: StringBuilder vs String concatenation in toString() in Java 18 answers When should we use + for concatenation of strings, when is StringBuilder preferred and When is it suitable to use concat. I've heard StringBuilder is preferable for concatenation within loops. Why is it so? Thanks. 回答1: I tend to use StringBuilder on code paths where performance is a concern. Repeated string concatenation within a loop is often a good candidate. The reason to prefer StringBuilder is that both + and