Need help in parsing this string

Hi guys,
I need help in parsing the below mentioned string.
RP50001,201232,London;RP50002,201392,USA
etc

What i want is, i first want to split it on the basis of ';' and after getting individual token i want to split it on the basis of ',' . There can be more in the string separate by ';' .

Any one recommend how can i do this? There is no SPLIT function as in c#.

Plzz help. Thanks

Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.

please like / agree / verify my answer, if it was helpful for you. thanks.

Best Answers

Answers

  • JuhlJuhl Member Posts: 724
    You can use .NET

    Take a look at this, i havent added a example for split, but if you know C#, then you should feel right at home.
    https://juhl.blog/2017/04/24/text-manipulation-using-net/
    Follow me on my blog juhl.blog
  • zohaibu95@hotmail.comzohaibu95@hotmail.com Member Posts: 223
    @Juhl , Thanks for the quick reply juhl. Actually i want to do it without DotNet variable so i am looking out for the ways through which we can parse this string (by looping and conditions).

    Looking forward.
    Best Regards
    Zohaib Ahmed
    Dynamics NAV ERP Technical Consultant.

    please like / agree / verify my answer, if it was helpful for you. thanks.
  • NavNabNavNab Member Posts: 181
    Hi,

    As suggested, .NET is your friend. Here is an example:

    SemiColon := ';';
    Comma := ',';

    String := 'RP50001,201232,London;RP50002,201392,USA';

    FOREACH SemiColonStrings IN String.Split(SemiColon.ToCharArray) DO BEGIN
    MESSAGE('%1', SemiColonStrings);
    FOREACH CommaStrings IN SemiColonStrings.Split(Comma.ToCharArray) DO BEGIN
    MESSAGE('%1', CommaStrings);
    END;
    END;

    where variables are:

    9xdci5p2l0ri.jpg
  • JuhlJuhl Member Posts: 724
    edited 2017-05-01
    Why not use the power of .NET ???

    It's translated into C# anyway
    https://juhl.blog/2017/04/24/cal-vs-c-i-dynamics-nav/
    Follow me on my blog juhl.blog
  • lubostlubost Member Posts: 628
    You can change semicolon to comma (if possible) and then split comma delimited string - for example by using SELECTSTR function.
  • zohaibu95@hotmail.comzohaibu95@hotmail.com Member Posts: 223
    edited 2017-05-02
    Thanks @ftornero . But there is issue in your code the pos is always remains 0 as a result it is causing issue.and only display RP50001 nothing else
    Best Regards
    Zohaib Ahmed
    Dynamics NAV ERP Technical Consultant.

    please like / agree / verify my answer, if it was helpful for you. thanks.
  • zohaibu95@hotmail.comzohaibu95@hotmail.com Member Posts: 223
    edited 2017-05-02
    Thanks @ftornero . I already did that :)
    Best Regards
    Zohaib Ahmed
    Dynamics NAV ERP Technical Consultant.

    please like / agree / verify my answer, if it was helpful for you. thanks.
  • ftorneroftornero Member Posts: 524
    zohaibu95 wrote: »
    Thanks @ftornero . I already did that :)

    Ok, and that solved the problem or not ?

    Regards
  • krikikriki Member, Moderator Posts: 9,115
    I am using this function since 2001 or so. Always served me well:


    Entry(PintEntry : Integer;PtexEntries : Text[1024];PtexSeperator : Text[1]) PtexReturnValue : Text[1024]
    // Entry
    // gives anentry of a list base on an integer
    // (like Navision SELECTSTR, but without bugs)
    // PARAMETERS :
    // PintEntry : which element must be returned
    // IF (PintElement <= 0) OR (PintElement > NumEntries(PtexEntries,PtexSeperator))
    // THEN '' is returned
    // PtexEntries : list
    // PtexSeperator : charakter used as seperator
    // if = '' then ',' is used
    // PtexReturnValue : selected element

    PtexReturnValue := '';
    LintLength := STRLEN(PtexEntries);

    IF (LintLength = 0) OR
    (PintEntry <= 0) THEN
    EXIT('');

    IF PtexSeperator = '' THEN
    PtexSeperator := ',';

    Lint := 0;
    WHILE Lint < LintLength DO BEGIN
    Lint := Lint + 1;
    IF COPYSTR(PtexEntries,Lint,1) = PtexSeperator THEN
    PintEntry := PintEntry - 1
    ELSE IF PintEntry = 1 THEN
    PtexReturnValue := PtexReturnValue + COPYSTR(PtexEntries,Lint,1);
    END;
    EXIT(PtexReturnValue);
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.