R
raylopez99
I see that String and StringBuilder in C# / C++ do not have an easy
way to set a string to null or zero length, once it is instantiated.
Apparently some variant of the .NET languages do (reading between the
lines from another fragment I found).
So the problem is to do this quickly (of course it can be done in a
roundabout manner), using either StringBuilder or String. I'm using
C#.NET version 2.0 (Visual Studio 2005). It looks like possibly
there's a new string class introduced in version 3.0 that has
a .remove or .clear public method?!
Ray Lopez
//////////////////// start
StringBuilder myString = new StringBuilder("Hello");
myString.Append(" World!");
Console.WriteLine("write out your string: {0}", myString); //Hello
World!
myString = null; //the intent here is to reset the string to a "" or
zero length string; obviously this is not the way to do this, as you
get a run-time error
Console.WriteLine(myString==null); // you get output: "True", since
myString is now null.
// this next line won't work--gives a runtime error, so the question
is: how to reset your string?
// myString.Append("my new string text for myString here, but gives a
runtime error!");
//////////////////// end
way to set a string to null or zero length, once it is instantiated.
Apparently some variant of the .NET languages do (reading between the
lines from another fragment I found).
So the problem is to do this quickly (of course it can be done in a
roundabout manner), using either StringBuilder or String. I'm using
C#.NET version 2.0 (Visual Studio 2005). It looks like possibly
there's a new string class introduced in version 3.0 that has
a .remove or .clear public method?!
Ray Lopez
//////////////////// start
StringBuilder myString = new StringBuilder("Hello");
myString.Append(" World!");
Console.WriteLine("write out your string: {0}", myString); //Hello
World!
myString = null; //the intent here is to reset the string to a "" or
zero length string; obviously this is not the way to do this, as you
get a run-time error
Console.WriteLine(myString==null); // you get output: "True", since
myString is now null.
// this next line won't work--gives a runtime error, so the question
is: how to reset your string?
// myString.Append("my new string text for myString here, but gives a
runtime error!");
//////////////////// end