Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 27, 2012 11:55 AM by bin hex
Member
2 Points
25 Posts
Apr 27, 2012 06:21 AM|LINK
Hi...
I want to extract a substring from a string....
the string would be, "CN=sample\,user,OU=DomainUsers,DC=ad,DC=com
now i want to extract sample\,user which is between CN= and ,
the main thing is i have to skip the escape sequence "\," How to do that in RegEx...
After getting sample\,user i want to convert it with out escape sequence... ie sample,user
I want RegEx to do this work...Can any RegEx-perts can help me?
228 Points
52 Posts
Apr 27, 2012 06:58 AM|LINK
hey
First thing i would like to tell you that we cannot read single back slash in a string so you have to take double back slash.
and then to get the output use the following code
String str = "CN=sample\\,user,OU=DomainUsers,DC=ad,DC=com"; Char[] sep = { '=' }; String[] arr = str.Split(sep); String str1 = arr[1].ToString(); String str4 = str1.Replace(",", "-"); Char[] sep1 = { '-' }; String[] arr1 = str4.Split(sep1); String str3 = arr1[0].ToString()+","+arr1[1].ToString(); Response.Write(str3.ToString());
Apr 27, 2012 07:16 AM|LINK
Hi Pooja,
Thanks for your Effort on this problem
I cant add Double Backslash Char because its system default(In Active Directory)...
And your logic will work only in this case...Consider i am having a string with "CN=sample user,OU=DomainUsers,DC=ad,DC=com", It wont work...
So RegEx will be the best soln...Where it searches for the string in between = and , (and it should skip the Escape Seq '\*')
Star
13591 Points
2571 Posts
Apr 27, 2012 08:48 AM|LINK
var x = str.Replace("\\,", "@#$%").Split(',')[0].Split('=')[1].Replace("@#$%",",");
I know it doesn't use a RegEx. Does it really matter?
Apr 27, 2012 11:55 AM|LINK
Thanks Linton!!! Your Logic is Awsome!!!! No words to describe...
bin hex
Member
2 Points
25 Posts
Need Regular Expression in C#....
Apr 27, 2012 06:21 AM|LINK
Hi...
I want to extract a substring from a string....
the string would be, "CN=sample\,user,OU=DomainUsers,DC=ad,DC=com
now i want to extract sample\,user which is between CN= and ,
the main thing is i have to skip the escape sequence "\," How to do that in RegEx...
After getting sample\,user i want to convert it with out escape sequence... ie sample,user
I want RegEx to do this work...Can any RegEx-perts can help me?
poojajoon
Member
228 Points
52 Posts
Re: Need Regular Expression in C#....
Apr 27, 2012 06:58 AM|LINK
hey
First thing i would like to tell you that we cannot read single back slash in a string so you have to take double back slash.
and then to get the output use the following code
String str = "CN=sample\\,user,OU=DomainUsers,DC=ad,DC=com";
Char[] sep = { '=' };
String[] arr = str.Split(sep);
String str1 = arr[1].ToString();
String str4 = str1.Replace(",", "-");
Char[] sep1 = { '-' };
String[] arr1 = str4.Split(sep1);
String str3 = arr1[0].ToString()+","+arr1[1].ToString();
Response.Write(str3.ToString());
bin hex
Member
2 Points
25 Posts
Re: Need Regular Expression in C#....
Apr 27, 2012 07:16 AM|LINK
Hi Pooja,
Thanks for your Effort on this problem
I cant add Double Backslash Char because its system default(In Active Directory)...
And your logic will work only in this case...Consider i am having a string with "CN=sample user,OU=DomainUsers,DC=ad,DC=com", It wont work...
So RegEx will be the best soln...Where it searches for the string in between = and , (and it should skip the Escape Seq '\*')
Paul Linton
Star
13591 Points
2571 Posts
Re: Need Regular Expression in C#....
Apr 27, 2012 08:48 AM|LINK
var x = str.Replace("\\,", "@#$%").Split(',')[0].Split('=')[1].Replace("@#$%",",");I know it doesn't use a RegEx. Does it really matter?
bin hex
Member
2 Points
25 Posts
Re: Need Regular Expression in C#....
Apr 27, 2012 11:55 AM|LINK
Thanks Linton!!! Your Logic is Awsome!!!! No words to describe...