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!

Is there a Mid Function (Excel Term) in VFP9? 1

Status
Not open for further replies.

Vatchunter

Technical User
Aug 21, 2004
43
US
Hi All,

I have a couple of instances where we get data that has been concatenated into one field. We need to strip out certain info but unfortunately, the characters we need to gather out of the string are not located consistently in the same place. Here's an example of the data:

6-25 4.1L 4.1 is the data I need...
4-7000 1.6L 1.6 is the data I need...

As always I appreciate your input!
 
In this case you can use getwordnum(yourtext,2) or val(getwordnum(yourtext,2))
 
Substr() is the equivalent to Mid().
To get 4.1 out of "6-25 4.1L" I'd use STREXTRACT, though. Looking for the space as left delimiter and L as right delimiter of the substring ou need. But that might just be the pattern in this case.

Besids there is GETWORDNUM() to get a certain word number of space separated string parts, you can also specify another separator than space, but mainly in this case GETWORDNUM(string,2) would be the 4.1L and 1.6L parts and striping off the L (as in the unit litres?) then could be a secondary processing, eg extracting the number in front of any unit via VAL().

So there are many ways to solve this, what's ideal depends.

Bye, Olaf.
 
www.excelfunctions.net/MidFunction.html said:
The Excel Mid function returns a specified number of characters from the middle of a supplied text string. An integer that specifies the position of the first character that you want to be returned.

The closest VFP Function might be SUBSTR() (which gets a sub-string from another string).
Use your VFP Help to find out more information.

One downside with attempting to use either function (MID() or SUBSTR()) is that you need to know ahead-of-time where (starting position and length) to extract your sub-strings.

If there is much variation in your Input Strings, you might want to consider using: GetWordNum( ) as recommended above.
Again, use your VFP Help to find out more information.

Olaf - sorry, it looks like you hit Submit Post before I did while I was still composing.

Good Luck,
JRB-Bldr

 
Thanks for the quick response.

The one thing that is consistent in the return I need is: the 1st character before and the 1st character after the decimal. The number of characters and or the use of the space will vary in the data.

Thanks,
 
[pre]lparameters tcText
return substr(tcText,at('.',tcText)-1,3)[/pre]
 
Appreciate all you replies.

tbleken that was exactly what we needed!

Thanks for giving me the alternatives solutions, with the GetWordNum() and following with a Substr() would have gotten me the vast majority of what I needed.

It's a good day when you can say you learned some new tricks!

vatchunter
 
Hi JRB-Bldr,

that just underlines it's what Vatchunter needs. Mid seems to be defined exactl the same way.

What will help find the position of the decimal point is AT('.',string)

Be, Olaf.
 
Vatchunter said:
I need is: the 1st character before and the 1st character after the decimal

OK - so what you need will always be exactly 3 characters
And those characters will always be around the decimal point.

So as long as there is only a single decimal point in the string you could try something like the following:
Code:
cStr = "4-7000 1.6L"
?SUBSTR(cStr,AT(".",cStr)-1,3)
 * --- and ---
cStr = "4-7000 1.6L"
?SUBSTR(cStr,AT(".",cStr)-1,3)

Good Luck,
JRB-Bldr



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top