I am trying to do an ldap lookup. I can pick up the domain name in the
standard format DOMAIN\USERNAME. The problem is the company I work for
expects the query in the format DOMAIN:USERNAME.
I tried to do a simple string replace to replace \ to : but it turns
out the only string you can't replace in c# is \ as it gives the
error "Invalid Escape Sequence" - using "\\" or @"\" doesnt work
either
// doesnt work
string result = Regex.Replace(string.Format("{0}", b), "\", ":");
Next step I tried was to convert the string to unicode and replace the
unicode \ with a unicode :
This works in terms of outputting to a label but does anyone know how
to convert a unicode sequence back to string values
Expand|Select|Wrap|Line Numbers
- string u1 = username.Text;
- UnicodeEncoding unicode = new UnicodeEncoding();
- Byte[] encodedBytes = unicode.GetBytes(u1);
- foreach (Byte b in encodedBytes)
- {
- string result = Regex.Replace(string.Format("{0}", b), "92", "58");
- // as output to a label to test result
- l1.Text += string.Format("{0}", result);
- }
useful. What I need to do is encode the unicode back to string and
pass that to my ldap code to perform the query (which works fine if I
hard code it).
What I tried to do was to create another Byte[] called decodedBytes
and add each parsed token from the first Byte[] and decode this when
complete.
Expand|Select|Wrap|Line Numbers
- String decodedString = unicode.GetString(decodedBytes);
know how to convert a unicode sequence back to string values.
Thanks