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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Right to left sort/index order

Status
Not open for further replies.

stepen123

Technical User
Jan 20, 2011
9
I have to arrange words in reverse order (right to left) to explore the suffixes. Here is an example: The Help says 'RightToLeft [property] is disregarded unless you are running a Middle Eastern version of Microsoft Windows.'

Is there a way to do it in VFP or Excel without changing the language settings?
 
Are you trying to sort on words in reverse order or all the characters in reverse order... I am assuming you don't mean
a simple descending order.

For characters, I would use a function like this:

Code:
? MyReverse("ABCD")

FUNCTION MyReverse
	PARAMETERS m.inString
	PRIVATE i,m.inString,m.outString
	m.outString = ""
	FOR i = 1 TO LEN(m.inString)
		m.outString = SUBSTR(m.inString,i,1) + m.outString 
	NEXT
Return(m.outString)

To do the same thing with words:

Code:
? MyReverseWord("ABCD EFGH IJKL")

FUNCTION MyReverseWord
	PARAMETERS m.inString
	PRIVATE i,m.inString,m.outString
	m.outString = ""
	FOR i = 1 TO GetWordCount(m.inString)
		m.outString = GetWordNum(m.inString,i) + " " + m.outString 
	NEXT
Return(m.outString)

The word based version is likely to be problematic if some kind of delimiter is used (commas periods etc).

Have Fun!

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
The idea being, as I neglected to say above, that you might index on the function you need.

use MyTable
index on MyReverse(MyFieldName) tag MyTag1
index on MyReverseWord(MyFieldName) tag MyTag2

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Stephen,

Griff has given you a good solution.

Just to clarify .... the RightToLeft property has got nothing to do with reversing the order of the letters in a word. It's concerned with the reading order of controls that contain text in a right-to-left language, such as Hebrew or Arabic.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
I was actually asking if there wasn't any way to this natively, some command option. Obviously there isn't.
In this case I'm going to use your code (thanks !) and convert all words in reverse order and then use traditional index commands.

The aim is to get a list of words ordered like this:
cicada
armada
RADA
autostrada
propaganda
..........
whizz
buzz
fuzz
(Might be useful for poetry :)
 
That might be closer to a phonetic order

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top