-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend string concatenation operator (&) to support StringBuilder as its left operand #114
Comments
I can see the benefits of this, but most of the time when I use a Also, I've always found using format strings with
Maybe if you concatenated a
|
@reduckted the idea is that you should get the same results so if your code says this today:
You should be able to change the type of Looking over it more, I think making |
That makes sense, though Your example raises another question. Does sb.Append("a").Append("b") or sb.Append("a" & "b") Also, don't forget that string concatenation is valid when the left-hand side is null, so this would need to initialise a new Dim sb As StringBuilder = Nothing
sb &= "abc" |
@AnthonyDGreen I'm using Dim s As New ScriptBuilder
s = s & $"123, this is {test}" ' StringBuilder.Append
s += "456" ' StringBuilder.AppendLine |
@xieguigang subtle. Very subtle. sciBASIC? |
Too subtle for my liking. That's just asking for hard-to-find bugs. |
3. Regarding AppendLineWith string interpolation, we can simply do Another option would be an operator specially for AppendLine like Maybe the best would be a newline-terminated string literal, which could be used everywhere. |
Concatenation is fine for simple cases but we've all had it drilled into us that StringBuilder is the way to go for successively building up large strings, particularly in loops, to avoid creating lots of very large garbage. The problem is that you have to completely change your code to go from one to the other. But, if we extend & to support StringBuilder on the left then most of the code could stay the same using
&=
and only the declaration of the variable would need to change to reap performance improvements.In short,
StringBuilder & <value>
would be defined to beStringBuilder.Append(<value>)
andStringBuilder &= <value>
would be defined asStringBuilder = StringBuilder.Append(<value>)
.The text was updated successfully, but these errors were encountered: