Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
X# examples - Reverse string
Message
From
23/10/2019 02:51:13
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Visual FoxPro and .NET
Title:
X# examples - Reverse string
Miscellaneous
Thread ID:
01671628
Message ID:
01671628
Views:
77
Likes (1)
Hi VFPers,

Thought I will create a new message. And seeing it was discussed in another thread, I thought it might be a good idea to do something similar using some of the features of .NET

Lets look at the basics of reversing a string: "12345" -> "54321", the recursive way. Yes you heard correctly Recursive
FUNCTION Reverse(cStr AS STRING) AS STRING
  RETURN iif(cStr.Length < 2, cStr, Reverse(cStr.Substring(1)) + cStr.Left(1))  && .NET 0 based
  && The good old XBase alternative
  RETURN iif(Len(cStr) < 2, cStr, Reverse(SubStr(cStr, 2))  + Left(cStr, 1))
ENDFUNC
Voila 1 line of code to reverse a string

Hope this is still of interest to some.
Johan Nel
George, South Africa
Friend of XSharp (FOX) member
E-mail : johan(dot)nel(at)xsinet(dot)co(dot)za
Web site : https://xsharp.info
X# runtime : https://github.com/X-Sharp/XSharpPublic
Radio talk : https://blog.aksel.com/2019/07/why-xsharp-might-be-tool-foxpro.html
Next
Reply
Map
View

Click here to load this message in the networking platform