Forum > Beginners

How to get the quantity of "LineEnding" of a string variable?

(1/3) > >>

Jvan:
Thanks.

dbannon:
That should take the award for shortest post for the day !

Do you mean the size, in bytes ?    if so, its 1 on Unix platforms, 2 on Windows

Or do you mean how many LineEndings there are in a string ? You count then them....

Davo

egsuh:
Or do you mean how many string matches with "LineEnding" within a string variable? ^^

lucamar:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses StrUtils; function LineEndCount(const sv: String): Integer;var  p: Integer;begin  Result := 0;  p := 0  repeat    p := PosEx(LineEnding, sv, p);    if p <> 0 then begin      Inc(Result);      Inc(p, Length(LineEnding));    end;  until p = 0;end;

MarkMLl:

--- Quote from: Jvan on May 13, 2021, 02:26:15 am ---Thanks.

--- End quote ---

Noting what other people have said and considering the vagueness of "quantity":

Pascal doesn't terminate string variables, so they have no explicit line ending, if by "quantity" you mean "what character is stored?".

The length of the string may be obtained by using Length(), if by "quantity" you mean "how much precedes the line ending?".

The runtimes are aware of the current OS so have a default line ending when writing, see https://www.freepascal.org/docs-html/current/rtl/system/defaulttextlinebreakstyle.html , if by "quantity" you mean "what character is written?".

Next time, ask a sensible question rather than leaving us all having to guess and wasting both your time and ours telling you things you might already know.

MarkMLl