Un-able to use StringBuilder class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to use the "replace" in the string builder class. I've imported the "system.text.stringbuilder" class into my project. However, I don't see the method call for "replace(oldchar,newchar,startindx,numofchars)" format.

It does not show up in intellisense.

What am I doing wrong. See below:

imports system.text.stringbuilder

Thanks
 
Larry,
Are you missing a little to your example?

You need to allocate a StringBuilder object, then you can invoke methods on
it.

Dim sb As New StringBuilder
sb.Replace("a"c, "b"c, 10, 100)

There are 4 overloads for the StringBuilder.Replace method.

Hope this helps
Jay

Larry Bird said:
I want to use the "replace" in the string builder class. I've imported
the "system.text.stringbuilder" class into my project. However, I don't see
the method call for "replace(oldchar,newchar,startindx,numofchars)" format.
 
Did you instantiate StringBuilder class?
For example:
Is there any cord like "Dim myStrBlder as StringBuilder" in your programm?
 
Hi,

Replace is only available to a stringbuilder variable.

Dim sb As New StringBuilder("Replace x with 10")

sb.Replace("x", "10")
Trace.WriteLine(sb.ToString)


Ken
----------------
 
| Here's a copy of my code:
|
| Imports System.Text.StringBuilder
|
| Dim xtemp as new Stringbuilder
|
| Stringbuilder in the above line displays the error: "stringbuilder not defined"
|
| As a result I'm not getting the replace method with intellisense and overload properties.
|
| Whats' wrong with this?
|
The StringBuilder class is contained in the System.Text namespace. Declaring a StringBuilder variable without importing the
appropriate namespace is done like so...

Dim xtemp As New System.Text.Stringbuilder()

If you want to declare your variable using the shortcut, only the namespace is required to be imported like so...

Imports System.Text

Dim xtemp As New Stringbuilder()

HTH,

ChrisG
 
* "=?Utf-8?B?TGFycnkgQmlyZA==?= said:
Imports System.Text.StringBuilder

Write 'Imports System.Text' instead. Importing the 'StringBuilder'
class there doesn't make sense.
Dim xtemp as new Stringbuilder

In the above statement "stringbuilder" displays the error:" stringbuilder not defined"

That's because the namespace 'System.Text' is not imported.
 
Back
Top