Options

Filter percentage out of string

ReSpongebobReSpongebob Member Posts: 17
Hi,

I would like to filter a percentage out of a string.

Example:

String: This ring is made of 15% pure gold

The result I need:
Var1: This ring is made of pure gold
Var2: 15%


Thanks in advance!

Comments

  • Options
    lzrlzr Member Posts: 264
    have you tried using copystr (copy part of the string) and strpos (find first position of a given substring)?
    Navision developer
  • Options
    ReSpongebobReSpongebob Member Posts: 17
    Thanks for the reply.

    I'm rather new to Navision and I don't know how I can filter a subset (0..9 |%|,) out of a string-variable.
  • Options
    AlbertvhAlbertvh Member Posts: 516
    Hi

    You could code it like this
    Text := 'this ring is made of 10% pure gold';
    Text3 := Text;
    WHILE STRPOS(Text3,'%') > 0 DO BEGIN
       Text3 := COPYSTR(Text3,STRPOS(Text3,' ') + 1);
       i := STRPOS(Text3,'%');
       IF (i < 6) AND
          (Text2 = '') THEN BEGIN
         Text2 := DELCHR(COPYSTR(Text3,1,i),'<>',' ');
         j := STRLEN(Text2);
       END;
    END;
    i := STRPOS(Text,'%');
    Text1 := COPYSTR(Text,1,i - j) + COPYSTR(Text,i + 2);
    MESSAGE('text = %1\Txt1 = %2\Txt2 = %3',Text,Text1,Text2);
    

    Albert
  • Options
    ReSpongebobReSpongebob Member Posts: 17
    Thanks a lot.
    =D>
Sign In or Register to comment.