Topic
11 replies Latest Post - ‏2013-04-06T20:04:17Z by llandale
btela2000
btela2000
19 Posts
ACCEPTED ANSWER

Pinned topic variation to partial string view from another attribute

‏2013-03-19T03:06:35Z |
Hello, thank you for the help thus far. I figureed out how to hard code if there are no IDs designated listed as "None" and simply show the same:

Object o
o= obj
Module m = current
string VerIds = o. "Verification IDs"

if (VerIds == "None") {
obj.attrDXLName = ("None")
} else {
obj.attrDXLName = (probeAttr_(obj, "Verification IDs"))[0:2]
}

I have carriage returns in my data, however, and I need to show multiple strings. For instance i have MEM1234
ELM1234
FLM1234

and I would want to show all three MEM, ELM, and FLM in my attribute. I guess I would need to separate the strings by carraige return (i think it's: "\n")

thanks, John
Updated on 2013-04-06T20:04:17Z at 2013-04-06T20:04:17Z by llandale
  • Mathias Mamsch
    Mathias Mamsch
    1762 Posts
    ACCEPTED ANSWER

    Re: variation to partial string view from another attribute

    ‏2013-03-19T08:25:44Z  in response to btela2000

    The normal technique that I use for concatenation is:
     

    void appendToBuffer (Buffer buf, string s) {
       if (length buf > 0) buf += "\n"
       buf += s
    }
     
    Buffer buf = create() 
     
    // append your strings here
     
    print stringOf (buf)
    obj.attrDXLName = buf
     
    delete buf
    

     


    Maybe that helps, regards Mathias

     

     


    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

     

    Updated on 2014-01-06T10:33:25Z at 2014-01-06T10:33:25Z by iron-man
  • llandale
    llandale
    2808 Posts
    ACCEPTED ANSWER

    Re: variation to partial string view from another attribute

    ‏2013-03-19T17:42:56Z  in response to btela2000

    Let me scribble, maybe you need to fix it.

    Object o
    o= obj
    Module m = current
    string VerIds = probeAttr_(obj, "Verification IDs")
     
    if (VerIds == "None") {
      obj.attrDXLName = "None"
    } else {
       Buffer bufResults = create()
       Regexp reLine = regexp2(".+")
       int LineNum = 0
       while(reLine VerIds)
       {  ThisId = VerIds[match 0]
          print "#" LineNum++ "\t[ThisId]\n"
          VerIds = VerIds[(end 0)+1:]   // ?? "+2" instead??
          if (length(bufResults) > 0) then bufResults += ", "
          bufResults += ThisId
       }   // end while
       obj.attrDXLName = tempStringOf(bufResults)
       delete(bufResults)
       delete(reLine)
    }
    


    The RegExp will match all characters up to the end of the string or the next EOL.

    -Louie

    Updated on 2014-01-06T10:33:44Z at 2014-01-06T10:33:44Z by iron-man
    • btela2000
      btela2000
      19 Posts
      ACCEPTED ANSWER

      Re: variation to partial string view from another attribute

      ‏2013-03-23T02:20:27Z  in response to llandale
      Hey folks, I truly appreciate the help in this! i have been trying to even comprehend your solutions. I have a ways to go!

      Louie, thank you so much for that sample code. I tried it out. I just added the simple prefix code to it here "{ ThisId = VerIdsmatch 0" and also used the +2 instead of +1 and it works(i also commented out the print code as it created errors)! thank you!

      Object o
      o= obj
      Module m = current
      string VerIds = probeAttr_(obj, "Verification IDs")

      if (VerIds == "None") {
      obj.attrDXLName = "None"
      } else {
      Buffer bufResults = create()
      Regexp reLine = regexp2(".+")
      int LineNum = 0
      while(reLine VerIds)
      { ThisId = VerIdsmatch 0][0:2]
      // print "#" LineNum++ "\tThisId\n"
      VerIds = VerIds[(end 0)+2:] // ?? "+2" instead??
      if (length(bufResults) > 0) then bufResults += ", "
      bufResults += ThisId
      } // end while
      obj.attrDXLName = tempStringOf(bufResults)
      delete(bufResults)
      delete(reLine)
      }}

      Louie, I would appreciate if you can direct me to some literature on the simple stuff as I'm still even trying to undertand your solution. I dont want to inidate you with simple questions and for you to get to the good stuff. Thanks again! John

      P.S. I'll have another question on this variation to this solution, i.e exceptions.
      • btela2000
        btela2000
        19 Posts
        ACCEPTED ANSWER

        Re: variation to partial string view from another attribute

        ‏2013-03-25T16:07:28Z  in response to btela2000
        Hey folks(especially Louie), thanks for the great help. The solution is almost there. I need to do these two last conditions and I'm good to go.
        1) I need to remove the duplicates (if the same prefix comes up more than once)...e.g MEM, MEM
        2) I need to introduce an if fucntion for a special condition whre I need to keep the first four characters [0:3] instead of the typical three ([0:2]...i.e. "THLM"
        • SystemAdmin
          SystemAdmin
          3180 Posts
          ACCEPTED ANSWER

          Re: variation to partial string view from another attribute

          ‏2013-03-25T16:29:20Z  in response to btela2000

          about 1) see my answer in your other thread of the same name that I posted a week ago (http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14960555). If you have any specific problems when programming this approach, tell me so.

          about 2) I assume that it would be better if you used a regexp to get the prefix of your ID instead of having solutions for 1, 2, 3, 4, 5 character prefixes, such as

          string sID = "MEM123"
           
          Regexp rePrefix = regexp "([a-zA-Z]+)[0-9]"
           
          string sPrefix = ""
          if (rePrefix sID) {
              sPrefix = sID[match 1]
          }
          print sPrefix
          


          (or, if you read this message via mail instead of browser)

           

          string sID = "THLM123"
           
          Regexp rePrefix = regexp "(\[a-zA-Z]+)\[0-9]"
           
          string sPrefix = ""
          if (rePrefix sID) {
              sPrefix = sID\[match 1]
          }
          print sPrefix
          



          HTH
          Mike



           

          Updated on 2014-01-06T10:34:19Z at 2014-01-06T10:34:19Z by iron-man
      • llandale
        llandale
        2808 Posts
        ACCEPTED ANSWER

        Re: variation to partial string view from another attribute

        ‏2013-03-25T17:50:54Z  in response to btela2000
        DOORS 'literature'? lol You know, I've been thinking about writing a DOORS novel.... experienced twit .. voodoo meister .. sadistic prison guard .. we got it all here.

        After sleeping on it, I think you need to do this instead:
        • Regexp reLine = regexp2(".*")
        to handle the case the input has an empty line.

        The loop finds the first match in the VerIds, deals with it, then strips off the matching part (and it's EOL; the "+2") from VerIds leaving the 'rest'.

        It may seem natural to other folks, but it seems unnatural to me that the normal regexp "end of string" has the meaning "end of string or end of line, which ever comes first". So when you search for 1 or more characters ".+" it really means "1 or more characters up to the end of line or end of string". Now, "end of line" is the '\n' character.

        If the original Vericiation IDs are these:
        • ABC123
        • BCD345
        • DEFxyz
        .. We should see three loops; where VerIds looks like this after the 1st loop:
        • BCD345
        • DEFxyz
        .. and after the 2nd:
        • DEFxyz
        .. and null after the 3rd

        If your delimiter was some other string, perhaps ", " then you'd have to do this differently. You could use a "non-greedy" version of [regexp "(.*)(, )"], but I would just search manually for ", " and not use regexp at all.

        -Louie
        • btela2000
          btela2000
          19 Posts
          ACCEPTED ANSWER

          Re: variation to partial string view from another attribute

          ‏2013-04-05T04:54:02Z  in response to llandale
          Hey guys, thanks for the great input. I've been chewing on this for a minute now. I will admit, I am still quite a novice. I stil need to learn basic C programming! bear with me, please! Louie, Mike, and Mathias thank you very much for your proposals.

          Mike, thanks for your original elegant solution. I tried a couple times with no success. I do like the principle of the skip list where it provides no duplicates.
          As of late I have been engrossed in this 'Customizing Telelogic DOORS using DXL' powerpoint that shows the basics of dxl. i'm getting there...may take a while tho! If you have any sample code for me i would appreciate it. I do like your regular expression approach that shows a true/fale whether theres an alphabetic character vs a number or digit. im looking into a variation to that for the isalpha true/false functuion. i also took a look at the string splitting solution but im having a hard time with the /(while reference thats in the dxl help.

          Louie, lol...let me know when you get that DXL Novel for Dummies written up! that'll be a NY Best Sellar!! So I'm tring to grasp your response and unfortunately its still somewhat greek to me! I did try the Regexp reLine = regexp2/(".*"/) but the dxl crashes. your code does work great for those where one takes the first three characters. im tring to understand how you can remove the duplicates...skip list? can a reqular expression be written where you look for alphabetical characters and when it comes true for the 4th character

          So after mulling this over with my coworker, I have come up with several alternate solutions. I have implemented one that is now link based(makes it much easlier to report) but that will require creating links to all the modules...which would be the long term solution. I already had code that supports that solution. I just want to solve this solution now anyways.

          I'm now thinking about doing a simple if statement where I would say that if the strings 4th characters is a alphabetical character then report the first four charqacters , else, report the first three characters. this is what i started with...im still trying to figure out how to separate the string based on either carriage return or comma.

          Object o
          o= obj
          Module m = current
          string VerIds = o. "Verification IDs"
          Skip IDlist = createString

          if (VerIds == "None") {
          obj.attrDXLName = ("None")
          } else {
          if VerIds(int4) isalpha then

          obj.attrDXLName = VerIds[0:3]
          else
          obj.attrDXLName = VerIds0:2

          }
          }

          Louie and Mike, I'm still intereted in undertanding your original solutions from earlier as well as this one. Thanks, John
          • llandale
            llandale
            2808 Posts
            ACCEPTED ANSWER

            Re: variation to partial string view from another attribute

            ‏2013-04-05T16:09:28Z  in response to btela2000

            Perhaps someone can come up with a more "elegant" solution:

            string sReg = "^([a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]|[a-zA-Z][a-zA-Z][a-zA-Z])(.*)"
            Regexp re = regexp2(sReg)
            print sReg "\n"
             
            void    Test(string In)
            {     string Suffix
                    if (re In) //
                    then 
                    {  print "Yes\t[" In "]\t" In[match 0] "\t" In[match 1] "\t" In[match 2] "\t"
                       Suffix       = In[match 1]
                       print "Suffix = \t>>" Suffix "<<\n"
                    }
                    else print "No \t[" In "]\n"
            }
            print "\tmatch:\t0\t1\t2\n"
            Test("ABC")           // "ABC"
            Test("AB0")           // fail
            Test("ABCD")  // "ABCD"
            Test("abcde") // "abcd"
            Test("ABC0")  // "ABC"
            Test("0ABC")  // Should fail
            Test("AA0ABC")        // Should fail
            

             


            -Louie

             

            Updated on 2014-01-06T10:34:40Z at 2014-01-06T10:34:40Z by iron-man
            • btela2000
              btela2000
              19 Posts
              ACCEPTED ANSWER

              Re: variation to partial string view from another attribute

              ‏2013-04-05T17:08:41Z  in response to llandale
              Hey Louie...thanks! I'll take a crack at it right now. hope i didnt offend you!!...you're the 'bawler' on this forum!! and thank you again for your lightening quick responeses!!
              • btela2000
                btela2000
                19 Posts
                ACCEPTED ANSWER

                Re: variation to partial string view from another attribute

                ‏2013-04-05T23:05:33Z  in response to btela2000
                Louie, I just tried out the code and yours looks like exactly what I need! lol...very 'Elegant!" here's where I tried to implement to my module thus far:

                string sResult = ""
                string sPrefix = ""
                string sReg = "^(a-zA-Za-zA-Za-zA-Za-zA-Z|a-zA-Za-zA-Za-zA-Z)\(.*\)"
                Regexp re = regexp2(sReg)
                //print sReg "\n"

                void Test(string In)
                { string Suffix
                if (re In) //
                then
                // { //print "Yes\t\t" Inmatch 0 "\t" Inmatch 1 "\t" Inmatch 2 "\t"
                Suffix = In0:3
                // print "Suffix = \t>>" Suffix "<<\n"
                }
                else Suffix = In0:2//print "No \t\n"
                }

                right now I am struggling how to create simple do loops and array definition to place the data strings in the final output. i now just simply got a book at our library for basic C programming. i will be continuing to read teh literature over the wknd. any help would be much appreciated.
                • llandale
                  llandale
                  2808 Posts
                  ACCEPTED ANSWER

                  Re: variation to partial string view from another attribute

                  ‏2013-04-06T20:04:17Z  in response to btela2000

                  No.

                  Look more closely at my test code and the printed results. "In[match 1]" is the matched string, if any. Since the 1st part of the "or" in the ReqExp has 4 digits, and the 2nd part has 3, ...

                  • [a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z] .. // 4-digit match
                  • | ................... // "Or"
                  • [a-zA-Z][a-zA-Z][a-zA-Z] .....// 3-digit match

                  it appears it will attempt to look for a 4 match before it attempts to look for a 3 match. Thus, if there is a 4-match then "In[match 1]" is 4 digits long.

                  Perhaps you want to take the 1st 3 characters if there is indeed no valid match.

                  I think your your case, if there is a match you want to use "In[match 2]" as the searched string for subsequent searches. Since that gets confusing (at least for me), I use the print statement of matches to help narrow it down. Something like this:

                  string Remainder = OriginalString
                  while (re Remainder)
                  {  Suffix = Remainder[match 1]
                     print Suffix "\tFound.\t[0]: " Remainder[match 0] "\t[1] " Remainder[match 1] "\t[2]: " Remainder[match 2] "\t[3]: " Remainder[match 3] "\n"
                     Deal with Suffix
                     Remainder = Remainder[match 2]     // must come after the print statement
                  }
                  print "After loop, Remainder =\t[" Remainder "]\n"
                  


                  -Louie

                  In order for your posts to show this:

                   

                  • In[match 0]

                  and not this:

                   

                   

                  You need to type this plain text:

                   

                   

                  • In\[match 0]

                  Unless it is within a "{code}" segment.

                   

                  Updated on 2014-01-06T10:37:00Z at 2014-01-06T10:37:00Z by iron-man