问题标签 [stringbuilder]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
5 回答
2770 浏览

asp.net - 创建动态链接的Stringbuilder问题

我在创建链接时遇到问题,例如"<a href="javascript:window.open('www.microsoft.com');">Visit Microsoft</a>使用 stringbuilder。我正在动态地将 html 添加到面板中,并且正在尝试创建一个弹出链接。

问题是由于某种原因链接被“混淆”了。例如:

给出的输出:

我不知道我做错了什么,它甚至对常规字符串做这种废话!

请帮忙!

0 投票
12 回答
170002 浏览

java - 在 Java 中读取 CLOB 到 String 和 String 到 CLOB 的最有效解决方案?

我有一个很大的 CLOB(超过 32kB),我想使用 StringBuilder 将其读取到字符串中。我如何以最有效的方式做到这一点?我不能为 StringBuilder 使用“int length”构造函数,因为我的 CLOB 的长度比“int”长并且需要一个“long”值。

我对 Java I/O 类不太满意,希望得到一些指导。

编辑-我已经尝试过使用这个 clobToString() 的代码:

0 投票
9 回答
1854 浏览

java - StringBuilder 和 ResultSet 性能问题的可能原因是什么

我在 Java 中循环一个 ResultSet;出于测试目的,它返回大约 30 行,每行 17 列(所有字符串数据)。我正在使用 StringBuilder 从结果中手动构建一个 XML 字符串,循环完成这些迭代实际上需要大约 36 秒。

注意:我意识到这不是从数据库中获取 XML 的最佳方法,甚至不是从 ResultSet 中获取 XML 的最佳方法 - 但这让我对性能缓慢感到好奇。

更新:根据到目前为止的回复,我必须解决以下问题:运行查询的时间不到一秒,并且我在代码的每个部分之前和之后都做了一个 System.currentTimeMillis() 来缩小范围。36 秒完全在下面的代码中。

更新:鉴于我收到的建议 - 这段代码花费的时间大致相同或花费半秒。

我做的最后一个测试消除了所有其他内容,是用实际数量的迭代替换 while 测试(160,从我之前完成的小测试返回的最大行数)。现在的问题是,这个结果集会导致如此缓慢的原因是什么。

更新:正如建议的那样,我将关闭这个问题,因为标题没有反映问题的方向。

0 投票
6 回答
91805 浏览

c# - 将 StringBuilder 写入 Stream

将 StringBuilder 写入 System.IO.Stream 的最佳方法是什么?

我目前正在做:

0 投票
3 回答
4186 浏览

asp.net - 复选框列表为字符串,保存到数据库,然后转换为数组

我知道这个主题可能有点奇怪,但我不确定如何准确描述我的目标

我正在尝试在内容管理系统中执行一些基于角色的权限。我能想到的最好方法是从数据库中提取角色列表并将它们放在 CheckBoxList 中。从那里,我将检查值的逗号分隔字符串保存到数据库的页面详细信息中。最后,当页面被拉回时,我通过拉下逗号分隔的字符串并将其拆分为 String() 并循环遍历值来检查当前用户是否具有权限。

我担心的是,当我遍历 CheckBoxList 并将值转换为字符串时,循环方法会在字符串的末尾添加一个逗号......然后我必须在将逗号保存到数据库之前去掉它。

我的问题是,有没有更好的方法来做到这一点,这样我就不必在保存之前返回字符串并去除尾随逗号?

0 投票
4 回答
468 浏览

.net - Does a StringBuilder initialized with a string contain exactly (only) enough space for that string?

I'm wondering if this code ...

... initializes sb with a buffer exactly as large as the string passed to the constructor. On the one hand, this would seem the most logical thing. On the other hand, it seems to kind of defeat the purpose of the StringBuilder class for one of its most common uses, which is to provide mutability to make repeated appends more efficient. (The very first call to Append, if the answer to my question is "yes", would require sb to resize itself.)

Then again, I suppose one could view this as analogous to the constructor for List<T> that takes an IEnumerable<T> as a parameter. Maybe the assumption in this case is that you're not planning on appending a lot, but rather on manipulating what's already there.

The only real research I've done on this was to check the MSDN documentation on StringBuilder, which didn't provide an answer (it says the constructor initializes the instance "using the specified string," but doesn't indicate how the string is used).


EDIT: So it's "implementation-specific"... does this not seem weird to anyone else? I mean, the purpose of the StringBuilder class is to offer an alternative to performing a lot of operations on a string, creating a ton of immutable string instances along the way; therefore, it's for efficiency. I feel like the behavior of this constructor ought the be specified, so that the developer can make an informed decision how to use it regardless of platform.

I mean, it is implemented by Microsoft a certain way; they could easily have put that in the documentation (forcing other implementations to follow suit). Just a personal source of puzzlement...

0 投票
3 回答
1863 浏览

java - java字符串缓冲区声明

当我不包含注释行时,prevLineBuffer 包含“null”。当我确实包含注释行时,它仍然可以工作,但会打印一个空字符串。Java 是否为声明的字符串静态分配空间,然后为注释行中的附加字符串动态分配空间?两者似乎都有效...

0 投票
3 回答
6852 浏览

vb.net - Visual Basic - 将回车发送到电子邮件

如何将字符串发送到包含新行(回车)的电子邮件?

问题是我将字符串发送到电子邮件,而电子邮件会去掉回车符。

0 投票
3 回答
1103 浏览

c# - 有效使用 StringBuilder

我需要为数据表中的每一行附加一个 Sqlquery。我有 36 列,并且根据每列的数据类型,我需要附加 sqlquery。任何人都可以建议我这样做的有效方法。它是不好的编码方式吗? “+”运算符在追加之间追加文本?

谢谢,维克斯

0 投票
2 回答
1652 浏览

c# - StringBuilder 和 JSON 的问题

我正在尝试在 C#.NET 中执行此代码,以将 SQL 表转换为具有正确 JSON 的字符串;

但是它不允许我在 {0} 和 {1} 索引之间使用逗号分隔。以下工作正常;

我究竟做错了什么?