By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,312 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

Stringbuilder and tostring

P: n/a
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
Jul 24 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"Egghead" <robertlo@NO_SHAW.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/>

Jul 24 '07 #2

P: n/a
Hi here,

I should have an example :)

dim cc as new stringbuilder
cc.append("abcde      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]" <hi***************@gmx.atwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"Egghead" <robertlo@NO_SHAW.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/>

Jul 24 '07 #3

P: n/a
On Jul 24, 4:56 pm, "Egghead" <robertlo@NO_SHAW.CAwrote:
Hi here,

I should have an example :)

dim cc as new stringbuilder
cc.append("abcde 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.atwrote in messagenews:%2****************@TK2MSFTNGP05.phx.gb l...
"Egghead" <robertlo@NO_SHAW.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

Jul 25 '07 #4

P: n/a
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 connectionString as string = connectionstring
Dim oConnection As New System.Data.SqlClient.SqlConnection(connectionStri ng)
Dim oSqlDataAdapter As New System.Data.SqlClient.SqlDataAdapter(dString,
oConnection)
Dim dTable As New System.Data.DataTable("dTable")
oConnection.Open()
oSqlDataAdapter.Fill(dTable)
Dim ss As New System.Text.StringBuilder
ss.Append(" " & vbCrLf)
ss.Append("-- Date : " & iDate.Trim & " -- " & vbCrLf)
For Each dd As DataRow In fTable.Rows
ss.Append(" X = : " & Convert.ToString(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" <du******@gmail.comwrote in message
news:11*********************@d55g2000hsg.googlegro ups.com...
On Jul 24, 4:56 pm, "Egghead" <robertlo@NO_SHAW.CAwrote:
>Hi here,

I should have an example :)

dim cc as new stringbuilder
cc.append("abcde 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.atwrote in
messagenews:%2****************@TK2MSFTNGP05.phx.g bl...
"Egghead" <robertlo@NO_SHAW.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

Jul 25 '07 #5

P: n/a
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....
http://www.yoda.arachsys.com/csharp/strings.html
....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

Jul 25 '07 #6

P: n/a
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" <Ro********@newsgroup.nospamwrote in message
news:b0**************************@msnews.microsoft .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....
http://www.yoda.arachsys.com/csharp/strings.html
...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

Jul 25 '07 #7

P: n/a
"Egghead" <robertlo@NO_SHAW.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.NullChar' or 'vbNullChar'.

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

Jul 25 '07 #8

P: n/a
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]" <hi***************@gmx.atwrote in message
news:uB**************@TK2MSFTNGP05.phx.gbl...
"Egghead" <robertlo@NO_SHAW.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.NullChar' or 'vbNullChar'.

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

Jul 25 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.