Options

Convert String

omyvadiyaomyvadiya Member Posts: 124
edited 2015-07-09 in NAV Three Tier
Hi,
How can i convert a dynamic string For Eg: A3BC TO ABBBC, 2A3B TO AABBB?

Thnx

Comments

  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    With just NAV it will be a lot of C/AL coding, but you can look at the DotNet string object and use all the C# string conversion tools, maybe that will help.
  • Options
    Rishi1109Rishi1109 Member Posts: 43
    Hi Omy ,

    As per the example provided by you , You can try the below mentioned code.

    OutputText:='';
    i:=0;
    REPEAT
       i:=i+1;
      IF EVALUATE(Char1,COPYSTR(InputText,i,1)) THEN;
         j := Char1;
         IF ((j>=48) AND (j<=57)) THEN BEGIN
           IF EVALUATE(j,FORMAT(Char1)) THEN;
           REPEAT 
            IF EVALUATE(Char2,COPYSTR(InputText,i+1,1))THEN;
            OutputText:=OutputText+FORMAT(Char2);
            j:=j-1;
           UNTIL j=1;
         END ELSE
           OutputText:=OutputText+FORMAT(Char1);
    UNTIL (i=STRLEN(InputText));
    

    i,j are integers
    Char1,Char2 are Characters
    InputText and Output Text are Text variables
    Thanks and Regards
    Rishi
  • Options
    omyvadiyaomyvadiya Member Posts: 124
    Thnx Rishi, it worked...

    although i tried the below code: but didn't :( worked:

    Procedure Replace (stOrig : Text[250];stOld : Text[250];stNew : Text[250]) : Text[250]


    IF stNew = stOld THEN
    EXIT(stOrig);

    i := 1;

    len := STRLEN(stOrig);
    len2 := STRLEN(stOld);

    REPEAT

    IF COPYSTR(stOrig,i,1) = COPYSTR(stOld,1,1) THEN
    BEGIN
    IF COPYSTR(stOrig,i,len2) = stOld THEN
    BEGIN
    st := st + stNew;
    i := i + len2-1;
    END
    ELSE
    st := st + COPYSTR(stOrig,i,1);
    END
    ELSE
    st := st + COPYSTR(stOrig,i,1);
    i := i + 1;
    UNTIL i = len+1;

    EXIT(st);
  • Options
    Rishi1109Rishi1109 Member Posts: 43
    Can you please tell me how would you call the function as you have taken 3 parameters.
    Thanks and Regards
    Rishi
  • Options
    thmartinthmartin Member Posts: 90
    By using a DotNET String object as variable in NAV the whole thing would look like:

    dotNetString := dotNetString.Replace(navStr1,navStr2);

    Variables:

    Name DataType Subtype Length
    dotNetString DotNet System.String.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    navStr1 Text
    navStr2 Text
    Thomas Martin
    NAV Developer
  • Options
    jversusjjversusj Member Posts: 489
    thank you for this, this was a great way to replace " with IN (inch) in an export.
    thmartin wrote:
    By using a DotNET String object as variable in NAV the whole thing would look like:

    dotNetString := dotNetString.Replace(navStr1,navStr2);

    Variables:

    Name DataType Subtype Length
    dotNetString DotNet System.String.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    navStr1 Text
    navStr2 Text
    kind of fell into this...
Sign In or Register to comment.