Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can I separate a string using a a number as the starting point and a comma as the ending point?

So here’s an example string:
CN=John Doe,OU=IT,OU=Management Support Services,OU=Divisions,OU=Accounts,DC=company,DC=com

I only need to get the first name out of this string. In this case the name being John Doe. I can’t hard code a number of characters in as the names there can vary in length.

Basically I need to select the string after CN= and then end it at the first comma.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The first number can always be 3 characters since the CN= is always there. Is there anyway for me to use the first comma as the end point?

I’m trying to do something like this.

let name = reports[i].mgrdn;
let result = name.split(3, ",")

Any help would be appreciated. Even just a suggestion about what method to use.

>Solution :

This will give you what you need.

 result = name.split(',')[0].split('=')[1];

Of course you should probably validate the format is what is expected too.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading