Find multiple strings with a string

dabba23dabba23 Member Posts: 77
Hey there :D

I am unsure how to write a piece code that take out multiple strings within a string.

My string can look as this:

#1234,#4567,#3456-ABJ,#9000,#9876-MEE
or
#1234,#4567,#3456-ABJ,#9876-MEE,#9000
or
#1234,#4567,#3456-ABJ,#9000

I want to take out those where there is a DASH:
#3456-ABJ and #9876-MEE

Can anyone help me :D

Thanks
Ann

Comments

  • WaldoWaldo Member Posts: 3,412
    I think you'll have to use a combination of "SELECTSTR" (Use this function to retrieve a substring from a comma-separated string) and "STRPOS" (Use this function to search for a substring inside a string).

    C/SIDE help can tell you more about these statements.

    You can put the SELECTSTR into an iteration by counting the comma's. You can do that by using statements like:
    strCommas := DELCHR(String,"=",DELCHR(String,'=',','));
    intNumberOfCommas := STRLEN(strCommas );

    I hope this is useful for you.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    You might also want to consider temporary tables.

    First you populate the temp table with all values and then filter on '-'
  • David_CoxDavid_Cox Member Posts: 509
    edited 2007-02-15
    This is an untested sample, you may have to adjust it.
    OldStr := '#1234,#4567,#3456-ABJ,#9000,#9876-MEE';
    
    //CommaSep and Hyphon are Integers
    REPEAT
        // Find The Comma
        CommaSep := STRPOS(OldStr,',');
        IF CommaSep <> 0 Then Begin
            // Find the Hyphon
            Hyphon := STRPOS(COPYSTR(OldStr,'-',1,commaSep));
            // Add Good Value add to the String
            IF Hyphon = 0 THEN
                NewStr := NewStr +  CopyStr(OldStr,1,CommaSep+1);
            //Trim Old string 
            OldStr := CopyStr(OldStr,CommaSep+1);
       End;   
    UNTIL CommaSep = 0;
    
    // Deal with the Last String
     Hyphon := STRPOS(COPYSTR(OldStr,'-'));
     // Add Good Value add to the String
     IF Hyphon = 0 THEN
         NewStr := NewStr +  OldStr;
    Message('%1',NewStr);
    
    
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • dabba23dabba23 Member Posts: 77
    Hey everyone,

    Thanks for the help. I managed to sort it out with your help:)

    Ann
Sign In or Register to comment.