-
Jul 1st, 2011, 11:03 AM
#1
[RESOLVED] StringBuilder
Is it just me? I do not understand why StringBuilder doesn't have an IndexOf and String does.
-
Jul 1st, 2011, 12:22 PM
#2
Addicted Member
Re: StringBuilder
I believe that may be because stringbuilder is a class to deal with some strings in more efficient ways than string does, and since strings are array of chars that may be why they have a IndexOf method.
-
Jul 1st, 2011, 01:28 PM
#3
Re: StringBuilder
your stringbuilder.tostring will.
StringBuilder isn't a string class... it's its own entity... it manages the string internally in a way that allows it to create and manipulate strings to avoid the memory issues associated with strings being immutable. The string itself isn't actually created until you call .ToString.
-tg
-
Jul 1st, 2011, 01:41 PM
#4
Re: StringBuilder
Originally Posted by Microsoft
We don't typically support many operations on StringBuildes, since we expect them to be fairly short-lived objects, that ultimately get turned into strings, and major operations performed upon those. Feel free to ping me directly if you have a particular reason why you're wanting to index on them!
http://connect.microsoft.com/VisualS...-stringbuilder
-
Jul 1st, 2011, 02:10 PM
#5
Re: StringBuilder
Originally Posted by Pradeep1210
It is closed and that is lame. I think it says we created stringbuilder and also expect you to use it like we intended, which we aren't going to document.
Let me put it this way; would the world of strings be better if stringbuilder had IndexOf?
-
Jul 1st, 2011, 02:14 PM
#6
Re: StringBuilder
I think all they meant to say is that developing such functions on StringBuilder is not so easy. So they have left it out (maybe for the time being), since the alternative of using String is already there.
-
Jul 1st, 2011, 02:28 PM
#7
Re: StringBuilder
That was 2005. So it is just me that thinks this would be worthwhile.
-
Jul 1st, 2011, 02:47 PM
#8
Re: StringBuilder
I guess I don't see what the problem is... just call the indexof against the tostring... I mean it's no different than if I wanted to call the index of a date... I'd have to go through the tostring of that as well...
*shrug* Write an extension...
-tg
-
Jul 1st, 2011, 03:07 PM
#9
Re: StringBuilder
That is great as long as the strings aren't huge. But it is not uncommon to see
Dim s As String = SourceFile.ReadToEnd()
Calling tostring is certainly an option... It just didn't make sense to have something that dealt with strings more efficiently, but then cripple it. That is just my opinion.
-
Jul 1st, 2011, 03:18 PM
#10
Re: StringBuilder
It's intended design is to allow the BUILDing of strings... with out having the added overhead memory costs associated with normal strings when doing numerous concatenations. The string doesn't actually exist until you finally call ToString... until that point, it's dealt with in a different manner so that it's not constantly having to re-allocate new space to hold the string(s).
And I'm not sure I see how your SourceFile.ReadToEnd() has anything to do with the discussion... unless you're somehow reading the contents of the file in to a stringbuilder and then expecting to manipulate it from there...
-tg
-
Jul 1st, 2011, 03:26 PM
#11
Re: StringBuilder
I think I must be being obtuse, and that is not my intention. I'll just close this.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|