Taking the Null Character Out of a String

Taking the Null Character Out of a String

Let me describe the problem first:

I have a TYPE statement with two variables(appname & dbname). They both are pointing to a global variable that sets the maximum length of each to 8(eight) characters each.

I am trying to print the values inside a listbox using ADDITEM and concatenating the two strings right after the ADDITEM. When the first string has eight characters it prints perfectly, but otherwise, it simply omits the second string and prints just the first one.

My guess is that the empty spaces or the NULL CHARACTER are blocking the statement to read whatever comes after the first string, but the TRIM statement is not working and I cannot lower the number of characters assigned to them. Each string is assigned 8 characters including the NULL CHARACTER.

An easy way to fix this would be to use the Replace function (VB 6) to search the string and replace all Chr(0) characters with spaces, or some other insignificant character. If you don’t have the Replace function, do this:

Dim strSource As String  ' original valueDim strReplace As String ' new, cleaned stringFor i = 1 To Len(strSource)   If Mid(strSource, i, 1) = Chr(0) Then      strReplace = strReplace & " "   Else      strReplace = strReplace & Mid(strSource, i, 1)   End IfNext i
See also  Monetize TikTok For Your Business

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist