Topic
3 replies Latest Post - ‏2009-04-17T10:12:50Z by Tony_Goodman
ManuelFelger
ManuelFelger
71 Posts
ACCEPTED ANSWER

Pinned topic How to count characters in a string?

‏2009-04-17T08:03:10Z |
Hi Guys,

i've got a script that manages some access rights and now i'm facing a problem.
My inputs are pathes like "/ProjectA/Folder1/Folder2/MolduleI" and i want to split them in the path of every single item, it should look like this:
"/ProjectA"
"/ProjectA/Folder1"
"/ProjectA/Folder1/Folder2"
"/ProjectA/Folder1/Folder2/MolduleI"

My first idea was to count the slashes in the string, but i dont know how, can you help me?

Regards,
Manuel
Updated on 2009-04-17T10:12:50Z at 2009-04-17T10:12:50Z by Tony_Goodman
  • Tony_Goodman
    Tony_Goodman
    270 Posts
    ACCEPTED ANSWER

    Re: How to count characters in a string?

    ‏2009-04-17T09:38:18Z  in response to ManuelFelger

    You could do this by looping through the string and looking for the slashes, but if you are dealing with DOORS paths then the following might be more reliable/efficient:
     

    string sPath = "/AMG/Red/Green/Blue/Black"
     
    print(sPath "\n")
     
    ModName_ m = module(sPath)
     
    Folder f = getParentFolder(m)
     
    while (!null f)
    {
        print(fullName(f) "\n")
     
            f = getParentFolder(f)
    }
    
    Updated on 2013-12-18T19:46:57Z at 2013-12-18T19:46:57Z by iron-man
    • ManuelFelger
      ManuelFelger
      71 Posts
      ACCEPTED ANSWER

      Re: How to count characters in a string?

      ‏2009-04-17T09:55:46Z  in response to Tony_Goodman
      Thank you Tony, it works!

      Regards,
      Manuel
      • Tony_Goodman
        Tony_Goodman
        270 Posts
        ACCEPTED ANSWER

        Re: How to count characters in a string?

        ‏2009-04-17T10:12:50Z  in response to ManuelFelger

        Of course it works ;-)

        Here's how to do with strings:
         

        string sPath = "/AMG/Red/Green/Blue/Black"
         
        print(sPath "\n")
         
        int i = 0
         
        for (i = length(sPath) - 1; i > 0; i--)
        {
            if (sPath[i] == '/')
                {
                        print(sPath[0:i-1] "\n")
                }
        }
        
        Updated on 2013-12-18T19:47:29Z at 2013-12-18T19:47:29Z by iron-man