Re: chop, separate, split a STRING into sections?
- From: Tom Shelton <tom_shelton@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 03 Dec 2008 22:08:59 -0800
On 2008-12-04, Teme64 <teemuhh@xxxxxxxxx> wrote:
Terry Moreau wrote:
seems like a rather common and simple task for .NET, but I can't seemTom Shelton wrote:
to find any "elegant" way to do it without using MID or SUBSTRING and
code looping such as DO WHILE or FOR NEXT.
<Extension()> _
Public Function Chunk(ByVal str As String, ByVal chunkSize As Integer) As String()
Dim los As New List(Of String)
Dim i As Integer = 1
Dim temp As String
While True
temp = Mid(str, i, chunkSize)
If temp = String.Empty Then Exit While
los.Add(temp)
i += chunkSize
End While
Return los.ToArray()
End Function
That function still uses Mid and While loop. Terry Moreau asked for
an "elegant" solution. Does calling the function to an extension method
make it an "elegant" solution?
I do admit it's an elegant example, how to use extension methods :)
While first off, I don't see the problem with mid, substring, or looping :)
But, I would definately want something like this encapsulated some how. I
figure a custom extension method looks good - because it appears to be a
member of string, even though it's not. And, it will probably end up being
faster then using a linq type query...
--
Tom Shelton
.
- References:
- chop, separate, split a STRING into sections?
- From: Terry Moreau
- Re: chop, separate, split a STRING into sections?
- From: Teme64
- chop, separate, split a STRING into sections?
- Prev by Date: Re: Start an Application Remotely
- Next by Date: Re: chop, separate, split a STRING into sections?
- Previous by thread: Re: chop, separate, split a STRING into sections?
- Next by thread: Re: chop, separate, split a STRING into sections?
- Index(es):
Relevant Pages
|