• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get cn value from below string  RSS feed

 
Nag Venkat
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cn=hitendrasunkara,ou=009,ou=people,o=lds

in the above string cn value may change depending on the users.So how can i get that value
 
Nag Venkat
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we need to write a regular expression for retriving the value of cn ,so can any one help me, out of this
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried?
 
Nag Venkat
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iam new to this regular expression, we need to writea regular expression like this:get the string in between firstoccurence of = and ,
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Being new to something is an opportune time to experiment in order to learn it.

A regular expression may be overkill. Since the source string is a comma-delimited collection of values, why not just obtain the portion of the string you need using existing String methods. You might review the String API for ideas.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also...

You're coming in saying "I need to use THIS to solve my problem". You'd be better off saying "I need to solve this problem - what would be the best way to do it?"
 
Nag Venkat
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String str="cn=hitendrasunkara,ou=009,ou=people,o=lds";
String test[]=str.split("=");
String displayName=test[1];
System.out.println(displayName.replaceAll(",ou", ""));

this solved my issue
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hitendra sunkara wrote: String str="cn=hitendrasunkara,ou=009,ou=people,o=lds";
String test[]=str.split("=");
String displayName=test[1];
System.out.println(displayName.replaceAll(",ou", ""));

this solved my issue


Is the "cn" always the first key-value pair? Is it always followed by the "ou" key-value pair? Because if the answer to either of these questions is "no", your solution won't work.

Henry
 
Nag Venkat
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes cn and ou's will be constatnt every time..Only the value changes in it..when there is a different user cn="differentUser"
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hitendra sunkara wrote:yes cn and ou's will be constatnt every time..Only the value changes in it..when there is a different user cn="differentUser"


If the indexes are constant, then how about this?



Henry
 
Nag Venkat
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah it is an optimized one thnq Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!