delphicharacterricheditline-breaks

How to count characters in RichEdit without two characters that every new line gives?


I have problem with counting characters in richedit (Delphi XE). For every new line as a result i get two characters more but in text they not exists.

Example: Here are 15 characters, but richedit gives 17 because of new line.

line zero
line one

Is there solution for this?


Solution

  • Remove CR/LFs and get the count of the remaining characters. An example:

    NumChars := Length(StringReplace(RichEdit1.Text, sLineBreak, '', [rfReplaceAll]));