Searching RTF in Chinese

  • All my wptool richText control text are stored in a database. If there are Chinese words, they are stored as code start with \u. Now I want to run a sql query to retrieve some records with a certain Chinese word. How can this be done? Can Chinese words be stored in its original form instead of using the code?

    Thanks,
    Paul

    • Offizieller Beitrag

    \u is translated to 2 byte unicodes.

    So in case you use Delphi 2009 or later it should be possible to serach for the text.

    There are also the TParagraph functions

    function HasTextW(w: WideString; AlsoCheckChildren: Boolean = TRUE;
    IgnoreCase: Boolean = FALSE): Boolean;

    function QuickFind(W: WideString; CompareAsLowercase: Boolean = FALSE; StartPos: Integer = 0): Integer;

  • I have the wpRichText content saved to the field "Notes" in the table note. I want to retrieve records with Notes field contains the word 奇特 using the following sql:
    select * from note where Notes like '%奇特%'

    Obviously, this sql will retrieve 0 record because "奇特" is stored differently in RTF. I want to know if it is possible to store "奇特" as is instead using the \u code in RTF. If not, how can I convert the 奇特 into the \u code so I can use it in the sql select command. Also, users may enter Endlish word to do search as well. How can I decide when to convert the search word to \u code and when to use it as entered? The solution you gave it for finding the text in the editor, not to be used in a sql select command.

    Thanks,
    Paul

  • Thank you for posting the solution. Saving rtf text to another field as plain text is an option. I am trying to find a way without doing that. How about checking the search string first. If it is beyond a certain number in the code page, then convert the search string to the \u code and using it in the sql query? Do you know the function to convert a unicode string to the \u code? How does wpRichText decide to convert a string to \u code?

    Thanks,
    Paul

  • I tested the query:
    select * from note where Note like '%\u22312 ?\u22996 ?%'
    It works. I just want to know if there is a routine in wpRichText library to encode my search string entered in a TEdit control to the RTF "\uxxxx ?" code. Can you let me know that? Thanks, Paul