How to efficiently chunk long string

A

Anony

Hi All,

I'm trying to chunk a long string SourceString into lines of LineLength
using this code:

Dim sReturn As String = ""
Dim iPos As Integer = 0
Do Until iPos >= SourceString.Length - LineLength
sReturn += SourceString.Substring(iPos, LineLength) + vbCrLf
iPos += LineLength
Loop
sReturn += SourceString.Substring(iPos)

It's OK if the SourceString is less than 1 mb. But if it's over 5 mb, the
cost of time and machine resource is intolerable.
Does anyone has a better idea or a routine dealing with large SourceString?


Thanks and regards,
Anony
 
C

Cor Ligthert

Hi Anony,

Why are you sending a real "language.vb" question also to the dotnet.general
group.
The language.vb newsgroup is one of the groups where you get always an
answer.

Your answer (sended from the general group by the way),

For your problem is the stringbuilder

Roughly written beneath

I hope it helps?

Cor
\\\\
dim sb as System.text.Stringbuilder
Dim iPos as Integer
For i to SourceString.Length - lineLength - 1 'check this yourself I did not
check it at all
sb.append(Sour..... et & vbCrLf ) 'you can can keep that & that
goes inline
next
dim mystring as string = sb.tostring
///
 
G

Guest

The .NET framework is language indifferent. The problem he is having and your answer would be relevant for VB.NET, C#, C++, MSIL or probably any other language that uses the .NET framework. He could have posted this in the .NET Framework newsgroup also.
 
J

Jeff

Actually its not a real "language.vb" question but a .NET framework
question. The line gets blurred when dealing with a multi-language
framework. I don't mind the question in both places. Just my two cents...
 
C

Cor Ligthert

HI Jeff,

Everything is a framework question when it is dotnet.

And as I told I answered Anony from the general group, in this case it goes
about how to use a program language with the framework, for that are 4
newsgroup.

I am probably the one who encourages the most crossposting in the dotnet
newsgroups, however here it is to obvious a language question in my opinion.

Cor
 
J

Jeff

Hey Cor,
Everything is a framework question when it is dotnet.

Not really. VB.NET has different issues than C#, and vice versa. Does VB.NET
have a using clause? Does C# have an AddHandler function. These are language
specific items.
however here it is to obvious a language question in my opinion.

The string and stringbuilder are part of the .NET framework, not part of the
languages themselves. The problem the user posted is relevant to anyone
trying to do the same thing regardless of language. The answer you provided
would work regardless of .NET language, correct?

Actually I think that the posting could have been sent to .NET VB and .NET
Framework newsgroups.

Jeff
 
J

Jon Skeet [C# MVP]

Cor Ligthert said:
Everything is a framework question when it is dotnet.

And as I told I answered Anony from the general group, in this case it goes
about how to use a program language with the framework, for that are 4
newsgroup.

I am probably the one who encourages the most crossposting in the dotnet
newsgroups, however here it is to obvious a language question in my opinion.

I think you have a much broader idea of what counts as a language
question than I do, Cor. I agree with the others - it's a framework
question. The basic answer is "use a StringBuilder rather than string
concatenation" and there's nothing VB.NET-specific in that.
 
C

Cor Ligthert

Hi Jeff,

In the language.vb net group has Anony disconnected the newsgroup
microsoft.public.dotnet.general

There he has answers from not only me.

In the dotnet general group with exception from mine answer there are only
troll answers.

I hope this clears it.

Cor
 
J

Jeff

I hope this clears it.

No it doesn't and you didn't answer my question.

The answer you provided would work regardless of .NET language, correct? The
string and stringbuilder are part of the framework and not the VB.NET
language correct?

This is not only a VB.NET question(I agree it should be posted in VB.NET),
its a .NET Framework question also, and you could add on .NET framework
performance newsgroup also. I think the thread you guys have here would be
helpful for anyone using the string and stringbuilder framework classes.

I hope this is clear?

Jeff
 
C

Cor Ligthert

Hi Jon,

Only answering "use the stringbuilder" is a very simple answer because it
needs an import or reference to *system.text* the way you do that is very
language dependable.

I disconnected the language.vb group because I think this is more a question
for this newsgroup.

Cor
 
J

Jeff

But the question and answer has nothing to do with the Imports statement.
Its about how to use the stringbuilder class effectively in a specific
context, and when not to use the string class in a specific context. This is
language neutral and framework specific.
 
C

Cor Ligthert

But the question and answer has nothing to do with the Imports statement.
Its about how to use the stringbuilder class effectively in a specific
context, and when not to use the string class in a specific context. This is
language neutral and framework specific.

Have a visit to the newsgroup

microsoft.public.dotnet.language.vb

Only read the first months, you can learn a lot.

Cor
 
J

Jeff

I'm telling you from a C# and C++ point of view, the original question
posted here, and the answers given at VB.NET newsgroup are relevant to my C#
and C++ development in the .NET framework. My project uses string and
stringbuilder all the time. So I'm asking you PLEASE don't hijack a thread
to the VB.NET just because its posed in the VB.NET language. Take a look at
this newsgroup, framework newsgroup and the performance newsgroup, all sorts
of questions are asked in different .NET languages when it comes to the
framework classes.

Thank You
Jeff
 
J

Jon Skeet [C# MVP]

Cor Ligthert said:
Only answering "use the stringbuilder" is a very simple answer because it
needs an import or reference to *system.text* the way you do that is very
language dependable.

You're grasping at straws. A simple response of "Repeatedly use the
Append method of StringBuilder, in the System.Text namespace" is
perfectly adequate for anyone with any significant experience at all
with the language. If the poster then wishes to ask "How do I use a
namespace within VB.NET?" that's clearly a VB.NET question - but that's
a different matter.
 
J

Jon Skeet [C# MVP]

Cor Ligthert said:
Have a visit to the newsgroup

microsoft.public.dotnet.language.vb

Only read the first months, you can learn a lot.

Just because questions are answered on the VB.NET newsgroup doesn't
mean they wouldn't be answered here, and it *certainly* doesn't mean
that the question was VB.NET-specific.

I seem to remember you suggesting that an ADO.NET question should have
been posted on the VB.NET newsgroup despite the fact that it didn't
mention VB.NET at all, and it turned out that the OP was using C#
anyway.

Why are you so keen to get *all* questions on the VB.NET newsgroup?
 
J

Jon Skeet [C# MVP]

Cor Ligthert said:
In the dotnet general group with exception from mine answer there are only
troll answers.

That's a scandalous assertion, and one which frankly warrants an
apology to the many people who help people daily in the dotnet.general
group and who you've just insulted as being trolls.
 
C

Cor Ligthert

Hi Jon,

I have enough from you ever making comment on my posts.

When you can do it better show it, however not with telling what it is
wrong, but with giving the right answers and not with a dump link to that
Jon Skeet page where than is seldom a real answer.
Tell it to how to do it better.

I not saw any reply in this thread from Anony on any of your answers.

Do you know what it is called useless answering post of others without any
answer to the original poster only to try to get a next answer from the one
who answered?

You do that to much in my opinion.

However, you want it you get it.

Cor
 
C

Cor Ligthert

Hi Jon,

I correct it a little bit, that about the Jon Skeet page I should not have
written, for that I make my excuus, I was very angry.

Cor
 
J

Jon Skeet [C# MVP]

Cor Ligthert said:
I have enough from you ever making comment on my posts.

It's not like you never comment on mine :)
When you can do it better show it, however not with telling what it is
wrong, but with giving the right answers and not with a dump link to that
Jon Skeet page where than is seldom a real answer.

When I post a link to one of my pages, it usually gives the answer in
far more detail than I'm willing to type in a newsgroup post. I think
the fact that many others also post links to my pages is an indication
that your idea that there's "seldom a real answer" there is wrong.
Tell it to how to do it better.

I not saw any reply in this thread from Anony on any of your answers.

Indeed. Your suggestion of using StringBuilder had already answered the
question. That doesn't mean I can't comment on your eternal obsession
with getting people to post in the VB.NET newsgroup whether or not the
post actually has anything significantly VB-ish about it. I hope you'll
note that it's not only me suggesting that this question was perfectly
fine on the .general group, and that it was basically language-
agnostic.
Do you know what it is called useless answering post of others without any
answer to the original poster only to try to get a next answer from the one
who answered?

Could you try to rewrite that? I've no idea what you meant there.

You still owe the many dedicated posters on this newsgroup an apology,
IMO.
 
C

Cor Ligthert

Hi Jon,
Could you try to rewrite that? I've no idea what you meant there.

You still owe the many dedicated posters on this newsgroup an apology,
IMO.
Do you see how long this thread is.

Do you see how few usefull information is in it.

I think you owe the visitors of this newsgroup an apology by helping
creating that.

Do you know what is the name for people who make such long threads with only
one reason and that is to get an answer and answer again.

(Jeff (with that name) is in mine opinion not a regular visitor to this
newsgroup who place or answers himself here questions, I did a Google search
on that, when that was like that I had never written this.)

However he has given a good answer, it keeps for me that the way he was
anwering did give me the idea he was trolling me. If he sais he did not, I
am the first to make my appoliges as you should know. (By the way I never
have seen that done by you)

http://tinyurl.com/ywrep

(And the excuse about the site I wrote before your message, that excuse I
keep)


Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top