Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
String Concatenation with the - Operator
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00674235
Message ID:
00674246
Views:
22
Andrew,

It's a doc error. - removes the trailing spaces from the first operand and concatenates them to end of the result. This is ostensibly to create fixed width results. Since it's the same precedence level as +, they evaluate left to right. This explains why the third result has the embedded spaces.

>I've just been showing off VFP's great string handling capabilities to the class here in sunny Melbourne. Of course, I got side tracked and set a litle exercise to demo the difference between the - and + operators:
>
m.lcString1 = "Hello" + space(4)
>m.lcString2 = "World" + space(2)
>? "*" + m.lcString1 + m.lcString2 + "*"
>? len("*" + m.lcString1 + m.lcString2 + "*")
>? "*" + m.lcString1 - m.lcString2 + "*"
>? len("*" + m.lcString1 - m.lcString2 + "*")
>? "*" + m.lcString1 - space(1) + m.lcString2 - "*"
>? len("*" + m.lcString1 - space(1) + m.lcString2 - "*")
>Pretty normal sort of stuff
>This returns:
>
*Hello    World  *
>18
>*HelloWorld      *
>18
>*Hello     World*
>19
where I would expect it to return
>
*Hello    World  *
>18
>*HelloWorld  *
>14
>*Hello World*
>13
>This occurs in VFP5 and 7.
>From my reading of the docs, the - operator should "remove the trailing blanks from the element preceeding the operator, then join the two elements". What appears to be occurring is that the string is left the same length and the white space simply moved to the end.
>Anyone else consider this to be a bug, either in the docs or the program?
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Reply
Map
View

Click here to load this message in the networking platform