I'm trying to load a string for a DirectorySearch filter.
strFilter = "((objectClass=container)(cn=" & strParameter & "))"
It doesn't matter what the end characters are, they are not being added to the string. It always ends up as:
strFilter = "((objectClass=container)(cn=" & strParameter
This is so frustrating. I can't even add the end brackets subsequently. What is going on? Strings should NOT behave like this!
1 Answer 1
If strParameter contains a null-character (char 0) the rest of the string will usually not be rendered by most text editors/text viewers, even though it is actually there. This happens because the null-character is usually used to indicate the end of a string.
Try trimming any null-characters from your string and see if it fixes your problem:
strFilter = "((objectClass=container)(cn=" & strParameter.Trim(ChrW(0)) & "))"
More information:
If you in the future (for some reason) encounter a null-character in the middle of your string you can try removing all null-characters alltogether:
strFilter = "((objectClass=container)(cn=" & strParameter.Replace(ChrW(0), "") & "))"
strParametercontains a null-character (char 0) the rest of the string will usually not be rendered by most text editors/viewers, even though it is actually there. Try trimming null-characters from your string and see if it fixes your problem:strFilter = "((objectClass=container)(cn=" & strParameter.Trim(ChrW(0)) & "))".