• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to get cn value from below string

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you tried?
 
Nag Venkat
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah it is an optimized one thnq Henry
 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic