Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

Split text by new lines

(0) ShareShare
ReportReport
Posted on by 55

Hello guys,

I'm trying split a CSV-text into the array of separate lines. I have a Text array, where the CSV-text is stored, it looks like following:

"Header1, Header2, Header3

Value1, Value2, Value3

Value4, Value5, Value6"

In order to split the text I tried following constructions:

Text.Split('\n');

Text.Split('\\n');

Text.Split('\r\n');

Neither of the above mentioned versions work.

Maybe someone could advise what is the proper way to split text by new lines?

  • Johny Be Good Profile Picture
    Johny Be Good 55 on at
    RE: Split text by new lines

    Ah, yeah...

    I used the wrong type for the new line code

    Here is working version:

       procedure Parse(CSV: Text): List of [Text];

       var

           result: List of [Text];

           CRLF: Char;

       begin

           CRLF := 10;

           result := CSV.Split(CRLF);

           Exit(result);

       end;

  • Johny Be Good Profile Picture
    Johny Be Good 55 on at
    RE: Split text by new lines

    Hi Alok!

    Thank you for your reply!

    I tried your advice, but it didn't work, maybe I did something wrong.

    I used following file as an example - people.sc.fsu.edu/.../addresses.csv

    ...

    Client.Get('people.sc.fsu.edu/.../addresses.csv', Response);

    Response.Content.ReadAs(Body);

    Exit(Utils.Parse(Body));

    ...

    codeunit 50100 Utils

    {

       procedure Parse(CSV: Text): List of [Text];

       var

           result: List of [Text];

           CRLF: Integer;

       begin

           CRLF := 13;

           result := CSVText.Split(Format(CRLF));

           Exit(result);

       end;

    }

    Also I tried 10 instead of 13, but it didn't work either

  • Verified answer
    Alok.kulshreshtha Profile Picture
    Alok.kulshreshtha 934 on at
    RE: Split text by new lines

    Hi

    Try below

    CRLF[1] := 13; (if 13 not work than try 10)

    Value1, Value2, Value3 + CRLF[1] + Value4, Value5, Value6

    Regards,

    Alok Kulshreshtha

    Please Verify my answer if you find my post helpful.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans