Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to check if the caret position in a TMemo is between two HTML tags Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
12-Oct-02
Category
Reporting /Printing
Language
Delphi 2.x
Views
162
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I need a string procedure that checks whether the caret position is between the 
tags '<>' , and if this is true, the contents of the tag are placed in a string for 
further processing.

Answer:

Something like this:
1   
2   function FindTextBetweenTags(const S: string; caretpos: Integer): string;
3   var
4     nStart, nEnd: Integer;
5   begin
6     Result := EmptyStr;
7     {caretpos is 0-based, string indices are 1-based}
8     Inc(caretpos);
9     {move backwards from caretpos util we find a '<'}
10    nstart := caretpos;
11    while ((nstart > 0) and (S[nstart]) <> '<') do
12      Dec(nstart);
13    if nstart = 0 then
14      Exit;
15    {move to first char after '<'}
16    Inc(nstart);
17    if S[nstart] = '>' then
18      Exit; {empty tag}
19    {move forward until we find a '>'}
20    nend := nstart;
21    while (nend <= Length(S)) and (S[nend] <> '>') do
22      Inc(nend);
23    if (nend > Length(S)) or (nend <= caretpos) then
24      Exit;
25    Result := Copy(S, nstart, nend - nstart);
26  end;


You would call it like

tagstring := FindtextBetweentags(memo1.text, memo1.selstart);

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC