web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

find a new line in a string

(0) ShareShare
ReportReport
Posted on by 161

Hi

As i am new to BC programming I am unsure of the correct syntax to find a new line in Text string. Can anyone advise?

As a test i am using the code to find the first '.'  (this works perfect!)
textstring := 'This is line1. this is line 2. this is line 3';
crpos := strpos(longtextleftover, '.');
but i want to change this to a new line.
textstring := 'This is line1
this is line 2
this is line 3';
crpos := strpos(longtextleftover, ???????? );

Any idea's appreciated. If it's a simple answer I apoloogise for my lack of knowledge in advance.
Thanks Neil.
I have the same question (0)
  • Lars Lohndorf-Larsen Profile Picture
    on at
    RE: find a new line in a string

    Hello,

    You got 2 out of 3 commands that you need :-), just add COPYSTR([String],[Position],[Length]);. Something like this:

       begin

           textstring := 'This is line1. this is line 2. this is line 3';

           LinePos := StrPos(TextString, '.');

           line1 := CopyStr(TextString, 1, LinePos);

           TextString := CopyStr(TextString, LinePos + 1);

           LinePos := StrPos(TextString, '.');

           line2 := CopyStr(TextString, 1, LinePos);

           TextString := CopyStr(TextString, LinePos + 1);

           line3 := TextString;

           Message(Line1 + '\' + Line2 + '\' + Line3);

       end;

       var

           TextString, Line1, Line2, Line3 : Text;

           LinePos: Integer;

    Note, I have not tested this, and likely I got a position wrong a few places, so it likely needs to be adjusted. Add more MESSAGE to see how the string develops.

    Once that works, of course then the next challenge would be to do this as a function, something like this:

    WHILE STRPOS(TextString,'.') <> 0 DO

     TextString := MyFunction(TextString);

    hth

  • Suggested answer
    YUN ZHU Profile Picture
    92,797 Super User 2025 Season 2 on at
    RE: find a new line in a string

    Hi, Lars' answer is very good, he splits the line based on the content of textstring.

    But I would like to add some basic information

    when you want to change a line in the text, just use '\'.

    For example:

    pastedimage1646874501625v2.png

    pastedimage1646874453219v1.png

    So use '\' will find a new line.

    A simple example:

    pastedimage1646874633017v4.png

    pastedimage1646874619736v3.png

    Hope this will help.

    Thanks.

    ZHU

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,045 Moderator on at
    RE: find a new line in a string

    If it is in a string you import or get from another system you can also use the CHAR datatype to search for the value 10 or 13 that is the char values for linefeed and carriage return.

  • Suggested answer
    Neil Phelan Profile Picture
    161 on at
    RE: find a new line in a string

    Thanks all for the help.

    I solved it using the following in the end...

    var

    typehelp: Codeunit "Type Helper";

    crlf: Text[2];

    begin

           crlf := typehelp.CRLFSeparator();

    textstring := 'This is line1

    this is line 2

    this is line 3';

    //find the first line break

    crpos := strpos(longtextleftover, crlf[2]  );

    end

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 4,285

#2
Sumit Singh Profile Picture

Sumit Singh 2,725

#3
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 2,526

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans