2 Replies Latest reply on Jun 23, 2010 10:15 AM by TiGGi

    Parse String?

    WestSide Level 1



      I have this string and I'm trying to take the string and convert it to an array using ListToArray.


      CN=SomeDL,OU=TestOU,DC=mysite,DC=domain,DC=com, CN=AnotherDL,OU=customOU,OU=Distribution Lists,DC=mysite,DC=domain,DC=com,CN=etc.etc.etc.etc.etc.


      I'm trying to grab everything between the "CN=" to right before the last comma where the next "CN=" will start.  So the array would look like (note how the trailing comma is not there either):




      [2]CN=AnotherDL,OU=customOU,OU=Distribution Lists,DC=mysite,DC=domain,DC=com





        • 1. Re: Parse String?
          Adam Cameron. Level 5

          Where's the data coming from?  At present you have a mix of "commas that are data" and "commas that are list delimiters", which makes for a poor and difficult-to-deal with data structure.  If you are in control of the code that generates that "list", it would be best to change the delimiter to something else (something that won't ever appear in an X.400 address would be sensible).


          I always use chr(29) - group separator - as my delimiter when building lists from data coming from a system outside my control (user-entered data, data from external systems, etc).


          If you don't have control over how the list is composed, then you'll need to do a regex replace of (",\s*CN") replacing it with something like "#someOtherDelim#CN", then use #someOtherDelim# as your list delimiter when parsing the list.



          • 2. Re: Parse String?
            TiGGi Level 1

            In this instance you would need to use string funtions (Find, FindNoCase, Mid..)


            Basicly you find first position using Find or FindNoCase function or if it's always at start of the string then you don't need.

            Then you find the position of your next "CN" starting from first "CN" position + 1 again using Find/FindNoCase, then you use MID function to grab the string between those 2 positions



            First CN Postiion = 1


            FindNoCase("NV",yourstringvariable,"2")  Brings back the position of your 2nd CN that finds starting from the second charachter in the string.

            So let's say it found 2nd CN at position 105.  Next thing to do is to grab everything from characther 1 to character 105 using MID function.

            Since you need to figure out how many characters you need to grab just substract first position from second position and you get 104.



            Hope it helps