Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove null characters from string in VB .NET

Status
Not open for further replies.

alan6895

Programmer
Aug 3, 2007
48
US
I have an ASP .NET 2.0 page that reads tags in from files. These tags are read as an absolute length (like take everything from byte 0 to 29). The problem is that when the info in the tags is less than the length read in, the code replaces it will null characters. Then, when I store the data in SQL Server it stores the null characters with it. Strangely, if I open a record in SQL Server to edit it, it ignore the null characters, so I can't remove them. When the data is then pulled from SQL Server in Firefox or Safari, the null characters show up as ???????. IE7 doesn't do this. So, my question is, does anyone know how I can strip off the null characters from the string before I even store the data in SQL Server? Thanks!
 
I'm storing it as an nvarchar(50). I was hoping that this setting would allow me to store special characters in the data (like accented letters), but that doesn't seem to be working either...
 
So after one more Google search and the discovery of the vbNullChar, I've fixed it. Now, the parameter inserted into the SQL command is run through String.Replace(vbNullChar, "") first.
 
It may have, but then I would need an extra step of counting the letters in a string before trimming.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top