Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / July 2007

Tip: Looking for answers? Try searching our database.

Stringbuilder and tostring

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Egghead - 24 Jul 2007 19:28 GMT
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.

Signature

Thanks,
RL

Herfried K. Wagner [MVP] - 24 Jul 2007 22:18 GMT
"Egghead" <robertlo@NO_SHAW.CA> schrieb:
> 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?

Signature

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

Egghead - 24 Jul 2007 22:56 GMT
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.

Signature

cheers,
RL

> "Egghead" <robertlo@NO_SHAW.CA> schrieb:
>> The toString method does not convert the whole StringBuilder elements. I
[quoted text clipped - 4 lines]
> are missing in the output?  How do you determine that characters are
> missing?
Chris Dunaway - 25 Jul 2007 14:26 GMT
> Hi here,
>
[quoted text clipped - 25 lines]
> > 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
Egghead - 25 Jul 2007 14:55 GMT
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(connectionString)
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.

Signature

cheers,
RL

>> Hi here,
>>
[quoted text clipped - 32 lines]
>
> Chris
Rory Becker - 25 Jul 2007 16:27 GMT
> 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?

--
Ror
Egghead - 25 Jul 2007 17:03 GMT
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

Signature

cheers,
RL

>> dim xs as string = ss.tostring  '<-The problem is that there are a
>> series of funny characters in the field causing the stringbuilder or
[quoted text clipped - 13 lines]
> --
> Rory
Herfried K. Wagner [MVP] - 25 Jul 2007 19:40 GMT
"Egghead" <robertlo@NO_SHAW.CA> schrieb:
> 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'.

Signature

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

Egghead - 25 Jul 2007 22:17 GMT
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
:)

Signature

cheers,
RL

> "Egghead" <robertlo@NO_SHAW.CA> schrieb:
>> 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'.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.