` Comment on an Icetips Article
Icetips - Templates, Tools & Utilities for Clarion Developers

Templates, Tools and Utilities
for Clarion Developers

Add a comment to an Icetips Article

Please add your comments to this article. Please note that you must provide both a name and a valid email address in order for us to publish your comment. Comments are moderated and are not visible until they have been approved. Spam is never approved!

Your Name:  
Email:  
Header text/Subject:  

Please enter your comment in the box below:

Back to article list   Search Articles     Add Comment     Printer friendly     Direct link  

Clarion in general: Finding end position of a StrPos search using Regular Expressions
2004-06-16 -- Michael Ware
 
Newsgroups: softvelocity.clarion.language I finally got a chance to play with this. The following function will return the match length: STRPOSLEN PROCEDURE(STRING sTEXT,STRING sEXP) X LONG StartPos LONG MatchLen LONG CODE StartPos = STRPOS(sTEXT,sEXP) MatchLen = 0 IF StartPos LOOP X = 1 TO (LEN(sTEXT) - StartPos) IF STRPOS(sub(sTEXT,StartPos, X),sEXP) MatchLen = x END UNTIL MatchLen END RETURN (MatchLen) -Mike "Bert Janssen" wrote in message news:1_134_1575@discuss.softvelocity.com... > > Hi Frank, > > Your solution work fine when the exact string to search is known. Since I need > to use regular expressions this is not the case. > > Example: > > Sentence 1: The tree is green. > Sentence 2: The tree is blue and green. > > Suppose I need to find the part between 'ee' and 'een' (this can be done using RE) > > Sentence 1 would return 'ee is green' > Sentence 2 would return 'ee is blue and green' > > STRPOS only returns the start of 'ee' =6 not the (variable) end position of 'een'. > > Regards, > > Bert Janssen > Océ Translation Services > http://www.oce.com > > > On Fri, Jun 11 2004, "Frank Vestjens" said: > >Bert, > > > >> Clarion STRPOS regular expressions returns the starting point of where > >your > >> expression matches. However if I need to replace this part I also need to > >know > >> how long the found part is. The length of the found part depends on the > >string, > >> so it's not always the same. > >> > >> Does anyone have a solution? > > > >Try this: > > > >!========================================================================== = > >= > >!PURPOSE : Replace Sequence Inside String > >!SYNOPSIS: StrReplace(OriginalString, SequenceToReplace, ReplaceWith) > >!========================================================================== = > >= > >StrReplace PROCEDURE(OrgString, ToSearch, ReplaceWith) > > > >Pos LONG(1) > > > > CODE > > LOOP > > Pos = INSTRING(ToSearch,OrgString,1,Pos) > > IF ~Pos THEN RETURN. > > > > OrgString = OrgString[1 : Pos-1] & ReplaceWith & OrgString[Pos + > >LEN(ToSearch) : LEN(OrgString)] > > Pos = Pos + LEN(ReplaceWith) > > END > > > >Regards, > > > >Frank Vestjens > >InforIT bv > > > > > > >


Today is May 2, 2024, 10:07 am
This article has been viewed 35123 times.
Google search has resulted in 296 hits on this article since January 25, 2004.



Back to article list   Search Articles   Add Comment   Printer friendly

Login

User Name:

Password: