C# -- String vs. StringBuilder

Results 1 to 2 of 2

Thread: C# -- String vs. StringBuilder

  1. #1
    SPG Guest

    Default C# -- String vs. StringBuilder

    I&#039;ve been converting some old VBScript string functions into C# and I&#039;ve encountered a sizeable snag -- the StringBuilder class is not (afaik) an actual String.<BR><BR>Why does it matter? Well, the StringBuilder class lets you do something like this --<BR> strBuilt.replace("&#060;", "&amp;lt;"); // Replace less-than with entity<BR>But only the String class will let you do something like this --<BR> strWeak.toUpper(); // or UCase(strWeak) for those of you at home<BR><BR>It would appear, at least to me, that this is why the MS evangelists got that goofy Barney-esque grin plastered on their faces when talking about "boxing and un-boxing" C# objects.<BR><BR>Will somebody please give me some good "you&#039;re working too hard again" news on how to get around this?<BR><BR>SPG (should&#039;ve stayed with Perl. Or Python. Or any language that knows that the web is based on strings.)

  2. #2
    Join Date
    Dec 1969

    Default RE: C# -- String vs. StringBuilder

    Normally I wouldn&#039;t answer this post since it would appear to a person knowledgable in this subject that your problem has been solved, but I think it&#039;s pretty safe in this forum since most people aren&#039;t familar with it.<BR><BR>I think String vs StringBuilder would be equivalent to Java&#039;s String vs StringBuffer...<BR><BR>String in Java, is absolute, and cannot be changed. When you change the contents, the entire memory is wiped clean and you&#039;re issued a new address. With a StringBuffer, you can append to the string.<BR><BR>So when you do this in Java:<BR><BR>String x = "Hello " + "World";<BR><BR>It REALLY is calling the StringBuffer Class and doing this:<BR><BR>String x = new StringBuffer().append("Hello").append("World").toS tring();<BR><BR>Hence, you have different methods avialable to you, because you&#039;re calling from 2 different classes. For instance, you have the String object .toUpperCase(), but it isn&#039;t avialable for the StringBuffer class (which appears to be your problem). Nuttin you really can do about it, me thinks.<BR><BR>I probably gave no insight on this problem, but thought it relates closely to what Java really does. Am I close at least?<BR><BR>"That&#039;s just my opinion, I could be wrong."<BR>--Dennis Miller

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts