.NETGURU
Better to create new Stringbuilder or remove
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngspeed' list.


Chan, Jasmine
-- Moved from [aspngdata] to [aspngspeed] by Charles M. Carroll <Click here to reveal e-mail address> --This message is in MIME format. Since your mail reader does not understandthis format, some or all of this message may not be legible.------_=_NextPart_001_01C19DEC.BD18AA3CContent-Type: text/plainHi all, In situations where you find yourself using the stringbuilder ina loop, is it better to call the remove method of the stringbuilder class toclear out the data or instantiate a new stringbuilder. For instance, I havea loop that go through and process my data. In the loop, I output the datain the string builder when certain criterias are met. Then I called theremove method to remove my data and start processing data again. Here is mypseudo-code: Dim sb as New StringBuilderFor i = 0 to list.count Select case type Case typ1 If count > limit then Console.writeline(sb.tostring) Sb.remove(0, sb.length) End if Sb.append(list.item(i)) Case typ2 If count > limit then Console.writeline(sb.tostring) Sb.remove(0, sb.length) End if Sb.append(list.item(i)) End SelectLoop Thanks in advance for your help. Jasmine ------_=_NextPart_001_01C19DEC.BD18AA3CContent-Type: text/htmlContent-Transfer-Encoding: quoted-printable<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =xmlns:w=3D"urn:schemas-microsoft-com:office:word" =xmlns:st1=3D"urn:schemas-microsoft-com:office:smarttags" =xmlns=3D"http://www.w3.org/TR/REC-html40";><head><META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =charset=3DUS-ASCII"><meta name=3DProgId content=3DWord.Document><meta name=3DGenerator content=3D"Microsoft Word 10"><meta name=3DOriginator content=3D"Microsoft Word 10"><link rel=3DFile-List href=3D"cid:filelist.xml@01C19DC2.3BF59110"><o:SmartTagType =namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags" name=3D"place"/><!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:DoNotRelyOnCSS/> </o:OfficeDocumentSettings></xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:DontDisplayPageBoundaries/> <w:DocumentKind>DocumentEmail</w:DocumentKind> <w:EnvelopeVis/> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:UseFELayout/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument></xml><![endif]--><!--[if !mso]><style>st1\:*{behavior:url(#default#ieooui) }</style><![endif]--><style><!-- /* Font Definitions */ @font-face    {font-family:PMingLiU;    panose-1:2 2 3 0 0 0 0 0 0 0;    mso-font-alt:\65B0\7D30\660E\9AD4;    mso-font-charset:136;    mso-generic-font-family:roman;    mso-font-pitch:variable;    mso-font-signature:3 137232384 22 0 1048577 0;}@font-face    {font-family:Georgia;    panose-1:2 4 5 2 5 4 5 2 3 3;    mso-font-charset:0;    mso-generic-font-family:roman;    mso-font-pitch:variable;    mso-font-signature:647 0 0 0 159 0;}@font-face    {font-family:"\@PMingLiU";    panose-1:2 2 3 0 0 0 0 0 0 0;    mso-font-charset:136;    mso-generic-font-family:roman;    mso-font-pitch:variable;    mso-font-signature:3 137232384 22 0 1048577 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal    {mso-style-parent:"";    margin:0in;    margin-bottom:.0001pt;    mso-pagination:widow-orphan;    font-size:12.0pt;    font-family:"Times New Roman";    mso-fareast-font-family:PMingLiU;    mso-fareast-language:ZH-TW;}h1    {mso-style-next:Normal;    margin-top:12.0pt;    margin-right:0in;    margin-bottom:3.0pt;    margin-left:.3in;    text-indent:-.3in;    mso-pagination:widow-orphan;    page-break-after:avoid;    mso-outline-level:1;    mso-list:l0 level1 lfo6;    tab-stops:list .3in;    font-size:18.0pt;    mso-bidi-font-size:16.0pt;    font-family:Arial;    mso-font-kerning:16.0pt;    mso-fareast-language:ZH-TW;}h2    {mso-style-next:Normal;    margin-top:12.0pt;    margin-right:0in;    margin-bottom:3.0pt;    margin-left:.4in;    text-indent:-.4in;    mso-pagination:widow-orphan;    page-break-after:avoid;    mso-outline-level:2;    mso-list:l0 level2 lfo6;    tab-stops:list .4in;    font-size:16.0pt;    mso-bidi-font-size:14.0pt;    font-family:Arial;    mso-fareast-language:ZH-TW;    mso-bidi-font-style:italic;}h3    {mso-style-next:Normal;    margin-top:12.0pt;    margin-right:0in;    margin-bottom:3.0pt;    margin-left:.5in;    text-indent:-.5in;    mso-pagination:widow-orphan;    page-break-after:avoid;    mso-outline-level:3;    mso-list:l0 level3 lfo6;    tab-stops:list .5in;    font-size:14.0pt;    mso-bidi-font-size:13.0pt;    font-family:Arial;    mso-fareast-language:ZH-TW;}h4    {mso-style-next:Normal;    margin-top:12.0pt;    margin-right:0in;    margin-bottom:3.0pt;    margin-left:.6in;    text-indent:-.6in;    mso-pagination:widow-orphan;    page-break-after:avoid;    mso-outline-level:4;    mso-list:l0 level4 lfo6;    tab-stops:list .6in;    font-size:14.0pt;    font-family:"Times New Roman";    mso-fareast-language:ZH-TW;}a:link, span.MsoHyperlink    {color:blue;    text-decoration:underline;    text-underline:single;}a:visited, span.MsoHyperlinkFollowed    {color:purple;    text-decoration:underline;    text-underline:single;}p.StyleHeading1Left0Firstline0, li.StyleHeading1Left0Firstline0, =div.StyleHeading1Left0Firstline0    {mso-style-name:"Style Heading 1 + Left\: 0\0022 First line\: =0\0022";    mso-style-parent:"Heading 1";    margin-top:12.0pt;    margin-right:0in;    margin-bottom:3.0pt;    margin-left:0in;    mso-pagination:widow-orphan;    page-break-after:avoid;    mso-outline-level:1;    font-size:18.0pt;    mso-bidi-font-size:10.0pt;    font-family:Arial;    mso-fareast-font-family:PMingLiU;    mso-bidi-font-family:"Times New Roman";    mso-font-kerning:16.0pt;    mso-fareast-language:ZH-TW;    font-weight:bold;}span.EmailStyle18    {mso-style-type:personal-compose;    mso-style-noshow:yes;    mso-ansi-font-size:11.0pt;    mso-bidi-font-size:11.0pt;    font-family:Georgia;    mso-ascii-font-family:Georgia;    mso-hansi-font-family:Georgia;    color:navy;    font-weight:normal;    font-style:normal;    text-decoration:none;    text-underline:none;    text-decoration:none;    text-line-through:none;}@page Section1    {size:8.5in 11.0in;    margin:1.0in 1.25in 1.0in 1.25in;    mso-header-margin:.5in;    mso-footer-margin:.5in;    mso-paper-source:0;}div.Section1    {page:Section1;} /* List Definitions */ @list l0    {mso-list-id:734739052;    mso-list-template-ids:-813929794;}@list l0:level1    {mso-level-style-link:"Heading 1";    mso-level-text:%1;    mso-level-tab-stop:.3in;    mso-level-number-position:left;    margin-left:.3in;    text-indent:-.3in;}@list l0:level2    {mso-level-style-link:"Heading 2";    mso-level-text:"%1\.%2";    mso-level-tab-stop:.4in;    mso-level-number-position:left;    margin-left:.4in;    text-indent:-.4in;}@list l0:level3    {mso-level-style-link:"Heading 3";    mso-level-text:"%1\.%2\.%3";    mso-level-tab-stop:.5in;    mso-level-number-position:left;    margin-left:.5in;    text-indent:-.5in;}@list l0:level4    {mso-level-style-link:"Heading 4";    mso-level-text:"%1\.%2\.%3\.%4";    mso-level-tab-stop:.6in;    mso-level-number-position:left;    margin-left:.6in;    text-indent:-.6in;}@list l0:level5    {mso-level-text:"%1\.%2\.%3\.%4\.%5";    mso-level-tab-stop:.7in;    mso-level-number-position:left;    margin-left:.7in;    text-indent:-.7in;}@list l0:level6    {mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6";    mso-level-tab-stop:.8in;    mso-level-number-position:left;    margin-left:.8in;    text-indent:-.8in;}@list l0:level7    {mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7";    mso-level-tab-stop:.9in;    mso-level-number-position:left;    margin-left:.9in;    text-indent:-.9in;}@list l0:level8    {mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8";    mso-level-tab-stop:1.0in;    mso-level-number-position:left;    margin-left:1.0in;    text-indent:-1.0in;}@list l0:level9    {mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.%9";    mso-level-tab-stop:1.1in;    mso-level-number-position:left;    margin-left:1.1in;    text-indent:-1.1in;}ol    {margin-bottom:0in;}ul    {margin-bottom:0in;}--></style><!--[if gte mso 10]><style> /* Style Definitions */=20 table.MsoNormalTable    {mso-style-name:"Table Normal";    mso-tstyle-rowband-size:0;    mso-tstyle-colband-size:0;    mso-style-noshow:yes;    mso-style-parent:"";    mso-padding-alt:0in 5.4pt 0in 5.4pt;    mso-para-margin:0in;    mso-para-margin-bottom:.0001pt;    mso-pagination:widow-orphan;    font-size:10.0pt;    font-family:"Times New Roman";}</style><![endif]--></head><body lang=3DEN-US link=3Dblue vlink=3Dpurple =style=3D'tab-interval:.5in'><div class=3DSection1><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'>Hi =all,<o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:1'>       &nbs=p;    </span>Insituations where you find yourself using the stringbuilder in a loop, =is itbetter to call the remove method of the stringbuilder class to clear =out thedata or instantiate a new stringbuilder. <spanstyle=3D'mso-spacerun:yes'> </span>For instance, I have a loop =that gothrough and process my data.<span style=3D'mso-spacerun:yes'>  =</span>In theloop, I output the data in the string builder when certain criterias =aremet.<span style=3D'mso-spacerun:yes'>  </span>Then I called the =removemethod to remove my data and start processing data again.<spanstyle=3D'mso-spacerun:yes'>  </span>Here is my =pseudo-code:<o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><o:p> </o:p></span></font></=p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'>Dim sb as New =StringBuilder<o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'>For i =3D 0 to =list.count<o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:1'>       &nbs=p;    </span>Selectcase type<o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:2'>       &nbs=p;           &nbs=p;    </span>Case<spanstyle=3D'mso-tab-count:1'>    =</span>typ1<o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:3'>       &nbs=p;           &nbs=p;           &nbs=p;    </span>Ifcount > limit then<span style=3D'mso-tab-count:1'>  =</span><o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:4'>       &nbs=p;           &nbs=p;           &nbs=p;           &nbs=p;    =</span>Console.writeline(sb.tostring)<o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:4'>       &nbs=p;           &nbs=p;           &nbs=p;           &nbs=p;    </span>Sb.remove(0,sb.length)<o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:3'>       &nbs=p;           &nbs=p;           &nbs=p;    </span>Endif<span =style=3D'mso-tab-count:2'>       &nbs=p;      </span><o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:3'>       &nbs=p;           &nbs=p;           &nbs=p;    </span>Sb.append(list.item(i))<spanstyle=3D'mso-tab-count:1'>       &nbs=p;   </span><o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:2'>       &nbs=p;           &nbs=p;    </span>Case<span style=3D'mso-tab-count:1'>   =</span>typ2<o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:3'>       &nbs=p;           &nbs=p;           &nbs=p;    </span>Ifcount > limit then<span style=3D'mso-tab-count:1'>  =</span><o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:4'>       &nbs=p;           &nbs=p;           &nbs=p;           &nbs=p;    =</span>Console.writeline(sb.tostring)<o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:4'>       &nbs=p;           &nbs=p;           &nbs=p;           &nbs=p;    </span>Sb.remove(0,sb.length)<o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:3'>       &nbs=p;           &nbs=p;           &nbs=p;    </span>Endif<span =style=3D'mso-tab-count:2'>       &nbs=p;      </span><o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:3'>       &nbs=p;           &nbs=p;           &nbs=p;    =</span>Sb.append(list.item(i))<o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><span =style=3D'mso-tab-count:1'>       &nbs=p;    </span>EndSelect<o:p></o:p></span></font></p><p class=3DMsoNormal><st1:place><font size=3D2 color=3Dnavy =face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'>Loop</span></f=ont></st1:place><fontsize=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><o:p> </o:p></span></font></=p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'>Thanks in advance for your =help.<o:p></o:p></span></font></p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><o:p> </o:p></span></font></=p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'>Jasmine<o:p></o:p></span></font><=/p><p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DGeorgia><span =style=3D'font-size:11.0pt;font-family:Georgia;color:navy'><o:p> </o:p></span></font></=p><p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =style=3D'font-size:12.0pt'><o:p> </o:p></span></font></p></div></body></html>------_=_NextPart_001_01C19DEC.BD18AA3C--
Reply to this message...
 
    
Chan, Jasmine
Hi all,
In situations where you find yourself using the stringbuilder in
a loop, is it better to call the remove method of the stringbuilder class to
clear out the data or instantiate a new stringbuilder. For instance, I have
a loop that go through and process my data. In the loop, I output the data
in the string builder when certain criterias are met. Then I called the
remove method to remove my data and start processing data again. Here is my
pseudo-code:

Dim sb as New StringBuilder
For i = 0 to list.count
Select case type
Case typ1
If count > limit then

Console.writeline(sb.tostring)
Sb.remove(0, sb.length)
End if
Sb.append(list.item(i))
Case typ2
If count > limit then

Console.writeline(sb.tostring)
Sb.remove(0, sb.length)
End if
Sb.append(list.item(i))
End Select
Loop

Thanks in advance for your help.

Jasmine
Reply to this message...
 
 
System.Console
System.Text.StringBuilder




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification