Stringbuilder and tostring

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Egghead

    #1

    Stringbuilder and tostring

    Hi all,

    A very weird problem here.

    The toString method does not convert the whole StringBuilder elements. I
    find out it is because there are a series of this " " inside the
    stringbuilder. Any idea how to replace those characters. I try to replace
    them with space before I append the String into the StringBuilder.


    --
    Thanks,
    RL


  • Herfried K. Wagner [MVP]

    #2
    Re: Stringbuilder and tostring

    "Egghead" <robertlo@NO_SH AW.CAschrieb:
    The toString method does not convert the whole StringBuilder elements. I
    find out it is because there are a series of this " " inside the
    stringbuilder.
    This should work. What are the character codes of the characters which are
    missing in the output? How do you determine that characters are missing?

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

    Comment

    • Egghead

      #3
      Re: Stringbuilder and tostring

      Hi here,

      I should have an example :)

      dim cc as new stringbuilder
      cc.append("abcd e      ede")
      dim st as string = cc.tostring
      st is only "abcde"

      The problem is that I do not know what is " ." I only find out the "
      " when I write the cc.tostring to a file.


      --
      cheers,
      RL
      "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrot e in message
      news:%23NYlkgjz HHA.4004@TK2MSF TNGP05.phx.gbl. ..
      "Egghead" <robertlo@NO_SH AW.CAschrieb:
      >The toString method does not convert the whole StringBuilder elements. I
      >find out it is because there are a series of this " " inside the
      >stringbuilde r.
      >
      This should work. What are the character codes of the characters which
      are missing in the output? How do you determine that characters are
      missing?
      >
      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

      Comment

      • Chris Dunaway

        #4
        Re: Stringbuilder and tostring

        On Jul 24, 4:56 pm, "Egghead" <robertlo@NO_SH AW.CAwrote:
        Hi here,
        >
        I should have an example :)
        >
        dim cc as new stringbuilder
        cc.append("abcd e ede")
        dim st as string = cc.tostring
        st is only "abcde"
        >
        The problem is that I do not know what is " ." I only find out the "
        " when I write the cc.tostring to a file.
        >
        --
        cheers,
        RL
        "Herfried K. Wagner [MVP]" <hirf-spam-me-h...@gmx.atwrot e in messagenews:%23 NYlkgjzHHA.4004 @TK2MSFTNGP05.p hx.gbl...
        >
        "Egghead" <robertlo@NO_SH AW.CAschrieb:
        The toString method does not convert the whole StringBuilder elements. I
        find out it is because there are a series of this " " inside the
        stringbuilder.
        >
        This should work. What are the character codes of the characters which
        are missing in the output? How do you determine that characters are
        missing?
        >
        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
        That is not the exact code that is causing your problem. I run that
        code and the string contains "abcde ede" as it should. So
        please show us and example that really reproduces the problem.

        Chris

        Comment

        • Egghead

          #5
          Re: Stringbuilder and tostring

          Hi here,

          The exact code is very similar. I believe it works in your PC is because of
          your newsreader filtering out the problematic characters.

          Dim dString as string = some select command
          Dim connectionStrin g as string = connectionstrin g
          Dim oConnection As New System.Data.Sql Client.SqlConne ction(connectio nString)
          Dim oSqlDataAdapter As New System.Data.Sql Client.SqlDataA dapter(dString,
          oConnection)
          Dim dTable As New System.Data.Dat aTable("dTable" )
          oConnection.Ope n()
          oSqlDataAdapter .Fill(dTable)
          Dim ss As New System.Text.Str ingBuilder
          ss.Append(" " & vbCrLf)
          ss.Append("-- Date : " & iDate.Trim & " -- " & vbCrLf)
          For Each dd As DataRow In fTable.Rows
          ss.Append(" X = : " & Convert.ToStrin g(dd("X")).Trim & vbCrLf)
          Next

          dim xs as string = ss.tostring '<-The problem is that there are a series of
          funny characters in the field causing the stringbuilder or string throught
          it reachs the end of the string already. If my select statement does not
          include those problematic rows, the string will have all the characters.


          --
          cheers,
          RL
          "Chris Dunaway" <dunawayc@gmail .comwrote in message
          news:1185369976 .905405.55260@d 55g2000hsg.goog legroups.com...
          On Jul 24, 4:56 pm, "Egghead" <robertlo@NO_SH AW.CAwrote:
          >Hi here,
          >>
          >I should have an example :)
          >>
          >dim cc as new stringbuilder
          >cc.append("abc de ede")
          >dim st as string = cc.tostring
          >st is only "abcde"
          >>
          >The problem is that I do not know what is " ." I only find out the "
          > " when I write the cc.tostring to a file.
          >>
          >--
          >cheers,
          >RL
          >"Herfried K. Wagner [MVP]" <hirf-spam-me-h...@gmx.atwrot e in
          >messagenews:%2 3NYlkgjzHHA.400 4@TK2MSFTNGP05. phx.gbl...
          >>
          "Egghead" <robertlo@NO_SH AW.CAschrieb:
          >The toString method does not convert the whole StringBuilder elements.
          >I
          >find out it is because there are a series of this " " inside the
          >stringbuilde r.
          >>
          This should work. What are the character codes of the characters which
          are missing in the output? How do you determine that characters are
          missing?
          >>
          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
          >
          That is not the exact code that is causing your problem. I run that
          code and the string contains "abcde ede" as it should. So
          please show us and example that really reproduces the problem.
          >
          Chris
          >

          Comment

          • Rory Becker

            #6
            Re: Stringbuilder and tostring

            dim xs as string = ss.tostring '<-The problem is that there are a
            series of funny characters in the field causing the stringbuilder or
            string throught it reachs the end of the string already. If my select
            statement does not include those problematic rows, the string will
            have all the characters.

            Perhaps you have nulls ('\0') in your string.

            The information here....

            ....suggests that this is fine in the strings themselves, but that...

            "many of the Windows Forms ones (classes) may well think that the string
            finishes at the first null character - if your string ever appears to be
            truncated oddly, that could be the problem."

            or perhaps a display issue with the vbcrlfs that you are injecting?

            --
            Rory



            Comment

            • Egghead

              #7
              Re: Stringbuilder and tostring

              Hi thanks,

              I thought there were some easy ways to replace any funny characters in the
              string. I tried the vblf, vbcr, vbcrlf, and it did nothing.
              BTW, how to repersent '\0' in VB.net? "\0" means \0 in VB.net

              --
              cheers,
              RL
              "Rory Becker" <RoryBecker@new sgroup.nospamwr ote in message
              news:b0ac48a017 71e8c99cefe062f c30@msnews.micr osoft.com...
              >dim xs as string = ss.tostring '<-The problem is that there are a
              >series of funny characters in the field causing the stringbuilder or
              >string throught it reachs the end of the string already. If my select
              >statement does not include those problematic rows, the string will
              >have all the characters.
              >
              >
              Perhaps you have nulls ('\0') in your string.
              The information here....

              ...suggests that this is fine in the strings themselves, but that...
              >
              "many of the Windows Forms ones (classes) may well think that the string
              finishes at the first null character - if your string ever appears to be
              truncated oddly, that could be the problem."
              or perhaps a display issue with the vbcrlfs that you are injecting?
              --
              Rory
              >
              >
              >

              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: Stringbuilder and tostring

                "Egghead" <robertlo@NO_SH AW.CAschrieb:
                I thought there were some easy ways to replace any funny characters in the
                string. I tried the vblf, vbcr, vbcrlf, and it did nothing.
                BTW, how to repersent '\0' in VB.net? "\0" means \0 in VB.net
                'ControlChars.N ullChar' or 'vbNullChar'.

                --
                M S Herfried K. Wagner
                M V P <URL:http://dotnet.mvps.org/>
                V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                Comment

                • Egghead

                  #9
                  Re: Stringbuilder and tostring

                  Hi thanks,

                  It is the nullchar. After I apply the replace method, I can convert the
                  whole string. The funny thing is that I get those funny characters as well
                  :)

                  --
                  cheers,
                  RL
                  "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrot e in message
                  news:uB3MLtuzHH A.4276@TK2MSFTN GP05.phx.gbl...
                  "Egghead" <robertlo@NO_SH AW.CAschrieb:
                  >I thought there were some easy ways to replace any funny characters in
                  >the string. I tried the vblf, vbcr, vbcrlf, and it did nothing.
                  >BTW, how to repersent '\0' in VB.net? "\0" means \0 in VB.net
                  >
                  'ControlChars.N ullChar' or 'vbNullChar'.
                  >
                  --
                  M S Herfried K. Wagner
                  M V P <URL:http://dotnet.mvps.org/>
                  V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                  Comment

                  Working...