stringbuilder

java.sql.SQLSyntaxErrorException: ORA-00955: name is already used by an existing object

匿名 (未验证) 提交于 2019-12-03 08:59:04
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using Oracle 11g R2, I want to create some user tables. When i run the query. It creates few tables and produces the java.sql.SQLSyntaxErrorException: ORA-00955: name is already used by an existing object Exception. Connection con=prepareConnection(); Statement st=con.createStatement(); StringBuilder sb=new StringBuilder(1024); sb.append("create table ").append(uname).append("(MESSAGES CLOB,LINKS VARCHAR2(150),FRIENDS VARCHAR2(50),COMMENTS CLOB,LIKES VARCHAR2(10),UNLIKES VARCHAR2(10),SHARES BLOB,QSTNS CLOB,ANS CLOB,UPDATES BLOB,THEMS

C# how to use WM_GETTEXT / GetWindowText API

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to get the content of the control / handle of an application.. Here's the experimental code.. Process[] processes = Process.GetProcessesByName("Notepad"); foreach (Process p in processes) { StringBuilder sb = new StringBuilder(); IntPtr pFoundWindow = p.MainWindowHandle; List s = GetChildWindows(pFoundWindow); // function that returns a //list of handle from child component on a given application. foreach (IntPtr test in s) { // Now I want something here that will return/show the text on the notepad.. } GetWindowText(pFoundWindow, sb

Comparison of String and StringBuilder manipulation in terms of memory usage

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: According to SCJP Study Guide by KathySierra: The java.lang.StringBuffer and java.lang.StringBuilder classes should be used when you have to make modifications to strings of characters. As we discussed, String objects are immutable, so if you choose to do a lot of manipulations with String objects, you will end up with a lot of abandoned String objects in the String pool To clear out this, I have gone through the code of String class and StringBuilder source here . The simplfied code of String looks like this: public final class String(){

Calling unmanaged function from C#: should I pass StringBuilder or use unsafe code?

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've got a C# program that needs to pass a char buffer to an unmanaged function. I've found two ways that seem to work reliably, but I'm not sure which I should choose. Here's the unmanaged function's signature. extern "C" __declspec(dllexport) int getNextResponse(char *buffer); The first option is to define the buffer as a StringBuilder, as follows. //at class level... [DllImport("mydll.dll")] static extern int getNextResponse(StringBuilder buffer); //in main method body... StringBuilder sb = new StringBuilder(" ", 65536); int rc =

Add an empty string vs toString - why is it bad?

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: According to the tool PMD, the following is a bad practice: String s = "" + 123; // bad String t = Integer.toString(456); // ok This is an inefficient way to convert any type to a `String`. Why is it a bad thing to do? 回答1: String s = "" + 123; // bad String t = Integer.toString(456); Will be compiled to: String s = "123"; String t = Integer.toString(456); so: "" +123 is obvious slightly better! Checked with JAD public static void main(String args[]) { // 0 0:ldc1 #16 <String "123"> // 1 2:astore_1 // 2 3:sipush 456 // 3 6:invokestatic #18

Dumping a Java StringBuilder to File

只愿长相守 提交于 2019-12-03 07:27:49
问题 What is the most efficient/elegant way to dump a StringBuilder to a text file? You can do: outputStream.write(stringBuilder.toString().getBytes()); But is this efficient for a very long file? Is there a better way? 回答1: As pointed out by others, use a Writer, and use a BufferedWriter, but then don't call writer.write(stringBuilder.toString()); instead just writer.append(stringBuilder); . EDIT: But, I see that you accepted a different answer because it was a one-liner. But that solution has

StringBuilder - Reset or create a new

。_饼干妹妹 提交于 2019-12-03 06:30:24
问题 I have a condition that a StringBuilder keeps storing lines matching a pattern from a large flat file (100's of MB). However after reaching a condition I write the content of the StringBuilder varialble to a textfile. Now I wonder if I should use the same variable by resetting the object -> stringBuilder.delete(0,stringBuilder.length()) OR stringBuilder=new StringBuilder(); Please suggest which would do you think is better as far as both performance and OOM issues are concerned. 回答1: I think

Is it required to check before replacing a string in StringBuilder (using functions like “Contains” or “IndexOf”)?

▼魔方 西西 提交于 2019-12-03 05:37:58
Is there any method IndexOf or Contains in C#. Below is the code: var sb = new StringBuilder(mystring); sb.Replace("abc", "a"); string dateFormatString = sb.ToString(); if (sb.ToString().Contains("def")) { sb.Replace("def", "aa"); } if (sb.ToString().Contains("ghi")) { sb.Replace("ghi", "assd"); } As you might have noticed I am using ToString() above again and again which I want to avoid as it is creating new string everytime. Can you help me how can I avoid it? If the StringBuilder doesn't contain "def" then performing the replacement won't cause any problems, so just use: var sb = new

StringBuilder.Append Vs StringBuilder.AppendFormat

♀尐吖头ヾ 提交于 2019-12-03 05:30:31
问题 I was wondering about StringBuilder and I've got a question that I was hoping the community would be able to explain. Let's just forget about code readability, which of these is faster and why? StringBuilder.Append : StringBuilder sb = new StringBuilder(); sb.Append(string1); sb.Append("----"); sb.Append(string2); StringBuilder.AppendFormat : StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0}----{1}",string1,string2); 回答1: It's impossible to say, not knowing the size of string1 and

StringBuilder append() and null values

こ雲淡風輕ζ 提交于 2019-12-03 04:22:33
I have a list of String s, and I want to concatenate them with spaces in between. So I'm using StringBuilder . Now if any of the String s are null , they get stored in the StringBuilder literally as 'null'. Here is a small program to illustrate the issue: public static void main(String ss[]) { StringBuilder sb = new StringBuilder(); String s; s = null; System.out.println(sb.append("Value: ").append(s)); } I'd expect the output to be "Value: " but it comes out as "Value: null" Is there a way around this problem? You can do a check on the object before appending it: sb.append("Value: "); if (s !