find first character

General TRichView support forum. Please post your questions here
Post Reply
adamrich
Posts: 35
Joined: Sun Feb 19, 2006 1:55 pm

find first character

Post by adamrich »

Hello,

Is there a way to find first character in TRichViewEdit?

I'm trying to find if the whole document is started with character @
I can't get the text of TRichViewEdit to see if copy(RichViewEdit1.Text, 1,1)='@'

Thank you
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: find first character

Post by Sergey Tkachenko »

You can use the function GetAllText from RVGetTextW.
But it is not efficient, you just need the first character, not the whole string that can be several megabytes.

I can write a function, but some details must be clarified:

1) What if the document is started from non-text object (such as picture or horizontal line)?
2) What if the document is started from several empty lines? Space characters? Tabs?
3) What if the document is started from a table, and '@' starts the first cell?
adamrich
Posts: 35
Joined: Sun Feb 19, 2006 1:55 pm

Re: find first character

Post by adamrich »

Thanks for your time,

All I need to know if the document's first character @ or whatever I look for ,
if picture or anything else other than @ or table etc, that means the first character not @ (excluding the space and empty lines)
example

@ abc, <table> hello world (first character is @ on the first paragraph )
@ (excluding the space, the first character is @)

even with more than one line, here the first line or paragraph empty or filled with space

@ (excluding the space, the first character is @)

abcd @ (@ not first character)
<table> @ </Table> (@ not first character)
<Picture> @ (@ not first character)

Hope I could explained clearly :)

Thank you
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: find first character

Post by Sergey Tkachenko »

This function returns the first non-space character (or #0, if the document is empty or started from non-text).
Empty lines, spaces and tab characters are ignored.

Code: Select all

uses
  RVUni;

function GetNonSpaceFirstChar(rv: TCustomRichView): TRVUnicodeChar;
var
  i: Integer;
  s: TRVUnicodeString;
begin
  Result := #0;
  for i := 0 to rv.ItemCount - 1 do
  begin
    if (rv.GetItemStyle(i) < 0) and (rv.GetItemStyle(i) <> rvsTab) then
      break
    else if rv.GetItemStyle(i) >= 0 then
    begin
      s := Trim(rv.GetItemTextW(i));
      if s <> '' then
      begin
        Result := s[1];
        break;
      end;
    end;
  end;
end;
adamrich
Posts: 35
Joined: Sun Feb 19, 2006 1:55 pm

Re: find first character

Post by adamrich »

Thank you,
As always I appreciate your superb support, you never let your user down, best support ever.

Thanks again
Post Reply