Microsoft KB Archive/114498

= INFO: Transposing First Character w/ Last Character in a Field =

Article ID: 114498

Article Last Modified on 3/3/2005

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft FoxPro 2.0
 * Microsoft FoxPro 2.6a Professional Edition for Macintosh

-



This article was previously published under Q114498



SUMMARY
The code in this article describes how to switch the first character with the last character in a field for all records.



MORE INFORMATION
The following code demonstrates an easy way to do this: * Replaces the field for each record REPLACE WITH RIGHT(TRIM,1)+; SUBSTR( ,2,LEN(TRIM)-2)+LEFT( ,1) ; FOR LEN(TRIM)>1 Before the commands are executed, a sample table may look similar to the following:    ---  A-0000-Z B-0-Y C-000000-X D-00000-W After the commands are executed, the table looks as follows:    ---  Z-0000-A Y-0-B X-000000-C W-00000-D The REPLACE command concatenates the original rightmost character with the a substring of the original value, which omitts the first and last characters, and appends the original leftmost character to that string.

This command works with variable-length character fields. With a few modifications, this code can be quite flexible and useful for string- manipulation purposes and can be adapted to work with other types of fields.

