Re: Parsing between a character and sysmbol
- From: "Scott M." <s-mar@xxxxxxxxxxxxx>
- Date: Sat, 19 Aug 2006 09:57:20 -0400
Notice that the OP asked for the digits that come before the '-' up to
the first non-digit. As the OP points out, in the example string, the
result should be the digits between "10AF" and "-25", i.e., 101.
No, I didn't notice that, but my code could easily be changed to accomodate
that.
Even if that was the case, notice that it's not recommended to build a
string like this, but to use a StringBuilder, instead.
Uh, no that is not true. StringBuilders are very good and I agree that for
large strings and large amounts of manipulations, StringBuilders are
effiient. But no one says strings shouldn't be built manually in all cases.
For small strings and limited amounts of manipulations, manually creating a
string is perfectly fine. In fact, in many cases, because of the intern
pool, there may be no gain in using StringBuilders. And actually, if the
string in question is small, using a StringBuilder may actually use MORE
memory than not using one.
Also, accessing array items inside a loop should be avoided whenever
possible.
That's ridiculous! Where did you get that from? One of the benefits of
arrays and collections is the ease of iterating through them via loops.
Your code is perfectly fine, but please don't make up best practices just to
bolster your code over others.
If the
OP had asked for all numeric chars before the '-', then a better method
would be:
Function ExtractDigits(Text As String) As String
Dim S As New System.Text.StringBuilder
For Each C As Char in Text
If C = "-"c Then Exit For
If Char.IsDigit(C) Then S.Append(C)
Next
Return S.ToString
End Function
Regards,
Branco.
.
- Follow-Ups:
- Re: Parsing between a character and sysmbol
- From: Branco Medeiros
- Re: Parsing between a character and sysmbol
- References:
- Re: Parsing between a character and sysmbol
- From: Scott M.
- Re: Parsing between a character and sysmbol
- From: GhostInAK
- Re: Parsing between a character and sysmbol
- From: Scott M.
- Re: Parsing between a character and sysmbol
- From: Branco Medeiros
- Re: Parsing between a character and sysmbol
- Prev by Date: Shared control tab
- Next by Date: Re: Parsing between a character and sysmbol
- Previous by thread: Re: Parsing between a character and sysmbol
- Next by thread: Re: Parsing between a character and sysmbol
- Index(es):
Relevant Pages
|