Re: Parsing between a character and sysmbol



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.



.



Relevant Pages

  • Re: [Info-Ingres] String Manipulations
    ... Subject: [Info-Ingres] String Manipulations ... create newtable1 as ...
    (comp.databases.ingres)
  • Re: Extract value from table cell
    ... Is there anyway I can do string ... > manipulations in VB for Microsfot word. ... You can go to Tools> References and add a reference to the Microsoft ...
    (microsoft.public.word.vba.beginners)
  • Re: Efficient fixed width string substition puzzle
    ... I am essentially dealing with data records similar to ... > is a string, StringBuilders, or character array. ... > manipulations, I want to grab a copy of the record as a string. ... It sounds like keeping it in a char array is indeed going to be ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can Turing machines do arithmetic?
    ... it's an issue of defining the string ... >>manipulations necessary to represent addition. ...
    (comp.programming)
  • Re: Introduction and Question re: Row Delimiter probs
    ... My preference for text ... > manipulations is PERL. ... > local string variable, and check the length of the string, then output ...
    (microsoft.public.sqlserver.dts)