Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Nov 22, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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 value
Dim strReplace As String ' new, cleaned string

For i = 1 To Len(strSource)
   If Mid(strSource, i, 1) = Chr(0) Then
      strReplace = strReplace & " "
      strReplace = strReplace & Mid(strSource, i, 1)
   End If
Next i
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date