Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. articles. downloads. faq. members. files. rss.
 From: Patrick C
  Where is Patrick C?
 St. Michael
 Barbados
 Patrick C
 To: António Lopes
  Where is António Lopes?
 Coimbra
 Portugal
 António Lopes
Subject: RE: An easier way to search string
Thread ID: 436296 Message ID: 436314 # Views: 52 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Projects and Design
Date: Saturday, May 7, 2016 1:18:26 AM         
   



> > I use this code to extract a potion of a word when a space is encountered:
> >
> >
> > BrandPartName=""
> > for i = 1 to len(alltrim(c_InvList.partName))
> >     if substr(c_InvList.partName,i,1) = spac(1)
> >        store substr(c_InvList.partName,1,i-1) to BrandPartName
> >        exit
> >     endi
> > endfor
> > if empty(Alltrim(BrandPartName))
> >    Store Alltrim(c_InvList.partName) To BrandPartName
> > endi
> > *wait wind 'BrandPartName :'+brandpartname
> > 
> > 

> >
> >
> > Is there a much simpler way - maybe the use of a VFP function - to do this?
> >
> > TIA
> >
> > Patrick
>
> Your code as an one-liner:
>
>
> BrandPartName = TRIM(EVL(STREXTRACT(ALLTRIM(c_InvList.partName),""," "),ALLTRIM(c_InvList.partName)))
> 

>
> [edit]
>
> and a shorter version:
>
>
> BrandPartName = TRIM(STREXTRACT(LTRIM(c_InvList.partName) + " ",""," "))
> 

>
> [/edit]


Hi Antonio,

Thanks very much. You code worked well for me. Just what I wanted.

Regards,

Patrick

ENTIRE THREAD

An easier way to search string Posted by Patrick C @ 5/6/2016 6:06:48 PM
RE: An easier way to search string Posted by Koen Piller @ 5/6/2016 6:29:14 PM
RE: An easier way to search string Posted by Patrick C @ 5/7/2016 1:09:07 AM
RE: An easier way to search string Posted by Paul Gibson @ 5/6/2016 7:21:48 PM
RE: An easier way to search string Posted by Patrick C @ 5/7/2016 1:16:13 AM
RE: An easier way to search string Posted by António Lopes @ 5/6/2016 8:39:18 PM
RE: An easier way to search string Posted by Patrick C @ 5/7/2016 1:18:26 AM
RE: An easier way to search string Posted by Rahul Moudgill @ 5/10/2016 7:19:01 AM