Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting variable length string using SELECT - VFP6

Status
Not open for further replies.

foxbldr

Programmer
Apr 16, 2002
109
CA
Hi All,

In a table, I have a character field called DESCRIP which look like:

xx bb zzz kk
x bbb zzzz kkk
xxx bb zzz kk
xx b zzz k

I want select Xs, Bs, Zs and Ks into four different fields and each value is separated by a space.

Whenever I write:

Select left(DESCRIP, AT(" ", DESCRIP,1)-1) as FLDX,.....

FLDX's length is determined by length of first record's X length (2 chars here) and setting FLDX length to 2.

Has anybody got a clue how to get strings without being trimmed without using a UDF or PADR (i.e PADR(left(DESCRIP, AT(" ", DESCRIP,1)-1), 20, " " )) ?

Help is much appreciated

Foxbldr






 
CREATE TABLE test (DESCRIP c(20))
INSERT INTO test values([xx bb zzz kk])
INSERT INTO test values([x bbb zzzz kkk])
INSERT INTO test values([xxx bb zzz kk])
INSERT INTO test values([xx b zzz k])

SELECT PADR(GETWORDNUM(DESCRIP,1,CHR(32)),5,SPACE(1)) as FLDX,;
PADR(GETWORDNUM(DESCRIP,2,CHR(32)),5,SPACE(1)) as FLDB,;
PADR(GETWORDNUM(DESCRIP,3,CHR(32)),5,SPACE(1)) as FLDZ,;
PADR(GETWORDNUM(DESCRIP,4,CHR(32)),5,SPACE(1)) as FLDK ;
FROM test
 
Hi Baltman,

Is Wordnum function availbale with VFP6?

Rgds
Foxbldr
 

Hi Foxbldr,

Is Wordnum function availbale with VFP6?

Yes, Words() and Wordnum() are present in Foxtools in VFP 6.0.

For versions 7.0 and above, the equivalent (and very useful) functins are GetWordCount() and GetWordNum().

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top