• Post Reply Bookmark Topic Watch Topic
  • New Topic

logical problem in string manipulation  RSS feed

 
Ranch Hand
Posts: 1085
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

i have a string and i need to do some manipulation with that.
i have tried couple of things but not sure if those are feasible or not.

here is the situation:

uid=aa\,bb,ou=people,cn=administrativeldap,cn=punit.punit.a-12-m020.20,o=ttt

i want the value of uid from this string, actually it's user id.
this particular string i want :: aa\,bb

Things which i have tried:

i was trying it in this way string start with uid and ends with ou, but in this case user name itself can have ou, so in that case it breaks.

another approach i was thinking of is splitting the string by = which gives me aa'',bb,ou at first position and then i will again split this string to remove ,ou. but i am not sure if this approach is good or not?

Thanks in advance.
 
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Split on comma that is not preceeded by "\" ? As I understood \ is an escape character here.

Output:
uid=aa\,bb
ou=people
cn=administrativeldap
cn=punit.punit.a-12-m020.20
o=ttt


Ther if you need it you can replace \, with , easily.
 
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to me that you don't know the exact conditions that make up a valid input String. With just one example, I have an easy solution for you: Get everything between the first '=' and the the second ','.

I suppose you won't like this solution, because it won't work for examples you haven't told us about. Without knowing specific constraints, this task is impossible.

Hint: it looks like every key-value pair is delimited using unescaped commas. It also looks like backslash is being used as an escape character.
 
Punit Jain
Ranch Hand
Posts: 1085
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys for the quick reply.

Stephan,

i can have = as well as multiple , in the username, so in that case it will again break if i split as suggested by you.

Pawel,

sounds good
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I said *unescaped* commas.

Pawel's solution should work swimmingly, but do you understand what it does?
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Punit Jain wrote:i was trying it in this way string start with uid and ends with ou, but in this case user name itself can have ou, so in that case it breaks.

Couldn't you do this, but search for ",ou=" instead of just "ou"?

 
Punit Jain
Ranch Hand
Posts: 1085
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but user name can also be like this ,ou=

yes but i can check this :: ,ou= which doesn't not have \ preceding to it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!