1

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!

Visual Vincent
18.4k5 gold badges33 silver badges83 bronze badges
asked Dec 6, 2017 at 15:08
7
  • Can you please show us some more code before that problematic line? Commented Dec 6, 2017 at 15:11
  • They don't... What is inside strParameter? do you check the value of strFilter right after it is set? Commented Dec 6, 2017 at 15:12
  • 2
    If strParameter contains 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)) & "))". Commented Dec 6, 2017 at 15:21
  • That ".Trim(ChrW(0)) " seems to be working. Thanks so much! Commented Dec 6, 2017 at 15:58
  • Glad I could help! I will write that as an answer so that you can mark this question as resolved. Commented Dec 6, 2017 at 19:20

1 Answer 1

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), "") & "))"
answered Dec 6, 2017 at 19:25
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.