RAt() and ChrTran() functions
-
- Posts: 774
- Joined: Wed May 17, 2017 8:50 am
- Location: Germany
RAt() and ChrTran() functions
Guys,
i looked at the VFP c#-Toolbox sources and implemented the RAt() - which supports an optinal occurrence param - and the ChrTran() function. See the attached viaef.
1. A right occurrence search is a bit tricky and using the c# code logic unchanged would sometimes throw a exception or show wrong results, but i think i made it. Because my FP-DOS doesn´t know a RAtC() func: Is it correct that there´s no VFP [center][/center] right search available that does a none case-sensitive search ? Both, RAt() and RAtC() do according the docs a case-sensitive search only, while At() does a case-sensitive and AtC() a none case-sensitive search ?
2. The only difference in the ChrTran() implementation is that i´m using the .net replace() method and not the StrTran() func like the Toolbox does.
Let me know if you find any problems.
regards
Karl-Heinz
i looked at the VFP c#-Toolbox sources and implemented the RAt() - which supports an optinal occurrence param - and the ChrTran() function. See the attached viaef.
1. A right occurrence search is a bit tricky and using the c# code logic unchanged would sometimes throw a exception or show wrong results, but i think i made it. Because my FP-DOS doesn´t know a RAtC() func: Is it correct that there´s no VFP [center][/center] right search available that does a none case-sensitive search ? Both, RAt() and RAtC() do according the docs a case-sensitive search only, while At() does a case-sensitive and AtC() a none case-sensitive search ?
2. The only difference in the ChrTran() implementation is that i´m using the .net replace() method and not the StrTran() func like the Toolbox does.
Let me know if you find any problems.
regards
Karl-Heinz
- Attachments
-
[The extension viaef has been deactivated and can no longer be displayed.]
RAt() and ChrTran() functions
Karl-Heinz,
Thanks.
We will review this and include this. Not in the upcoming 2.4 build but in the build after that.
Robert
Thanks.
We will review this and include this. Not in the upcoming 2.4 build but in the build after that.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
-
- Posts: 200
- Joined: Wed Oct 09, 2019 6:51 pm
RAt() and ChrTran() functions
Hi Kark-Heinz,
regards
thomas
Vfp RATC is documented to work case sensitive and does work so. I had wondered about similar name but different descriptions/implementations and asked about that - received an answer not clearly describing a bug, but perhaps miscommunication early on, like "MS sometimes follows mysterious paths"Karl-Heinz wrote:Both, RAt() and RAtC() do according the docs a case-sensitive search only, while At() does a case-sensitive and AtC() a none case-sensitive search ?
Have you checked perf on loooong strings? If perf gets worse relative to vfp chrtran() as strings grow a lot, working C-like on individual chars and replacing each on a once over scan of total string might be faster, depending on the work Replace() has to do on each replace (which might be not a single char, but another string). Calling CharArray.ToString at end might be worth it (dunno if calling String.ToCharArray() first will benefit over accessing single string elements), even if adding/replacing/doing nothing for each single char is certainly slower than doing a memCopy of all "in-between chars" of Replace(). But that again is offset by the length of the string with the chars searched for - in effect the in-between chars get memcopied SearchFor.Length times...2. The only difference in the ChrTran() implementation is that i´m using the .net replace() method and not the StrTran() func like the Toolbox does.
regards
thomas
RAt() and ChrTran() functions
@Karl-Heinz - When you said "VFP c#-Toolbox", do you mean "Visual FoxPro Toolkit for .NET"?
https://github.com/mattslay/Visual-FoxP ... t-for-.NET
https://github.com/mattslay/Visual-FoxP ... t-for-.NET
-
- Posts: 774
- Joined: Wed May 17, 2017 8:50 am
- Location: Germany
RAt() and ChrTran() functions
Hi Thomas,
Why not just simply do a VFP / X # ChrTran() speed comparison ? In the Start () there´s code where i´m using large strings.
my results are:
0,00 // up to 0,01 secs
.T. , 200000, 200000
BTW. I´m looking at some other interesting VFP funcs and noticed that the Quarter() function has an optional param nMonth. With this param it´s possible to retrieve the number of a financal quarter instead of the calender quarter.
What does VFP do if nMonth is < 1 or > 12 ? Does it throw a runtime error or does it return 0 ?
regards
Karl-Heinz
Why not just simply do a VFP / X # ChrTran() speed comparison ? In the Start () there´s code where i´m using large strings.
Code: Select all
VAR x := Replicate ( "A", 200000 )
VAR y := Replicate ( "I", 200000 )
VAR f := Seconds()
VAR g := ChrTran( x ,"A" , "IE" )
? Seconds() - f , "secs"
? g == y , SLen ( g ) , SLen (y )
0,00 // up to 0,01 secs
.T. , 200000, 200000
BTW. I´m looking at some other interesting VFP funcs and noticed that the Quarter() function has an optional param nMonth. With this param it´s possible to retrieve the number of a financal quarter instead of the calender quarter.
Code: Select all
QUARTER(dExpression | tExpression [, nMonth])
regards
Karl-Heinz
-
- Posts: 774
- Joined: Wed May 17, 2017 8:50 am
- Location: Germany
RAt() and ChrTran() functions
Yes !FoxProMatt wrote:@Karl-Heinz - When you said "VFP c#-Toolbox", do you mean "Visual FoxPro Toolkit for .NET"?
https://github.com/mattslay/Visual-FoxP ... t-for-.NET
regards
Karl-Heinz
- kevclark64
- Posts: 127
- Joined: Thu Aug 15, 2019 7:30 pm
- Location: USA
RAt() and ChrTran() functions
? QUARTER(date(), 0) ** throws runtime error "Function argument value, type, or count is invalid."
-
- Posts: 774
- Joined: Wed May 17, 2017 8:50 am
- Location: Germany
RAt() and ChrTran() functions
Guys,
i added the funcs GoMonth() and Quarter() to the viaef.
Quarter() throws a argument exception if the dwMonth value is < 1 or > 12. The dwMonth default value is 1, so at that point the fiscal quarter is equal to the calendar quarter.
@Robert
in the VFP docs i found that {//} creates a empty date, but trying that with X# throws the error:
XS9002: Parser: unexpected CRLF, are you missing a token ?
I´ve tried it with my FP-DOS dinosaur and the result is:
regards
Karl-Heinz
i added the funcs GoMonth() and Quarter() to the viaef.
Code: Select all
FUNCTION GoMonth( d AS DATE , iNumberOfMonths AS INT ) AS DATE
FUNCTION GoMonth( dt AS DateTime , iNumberOfMonths AS INT ) AS DATE
FUNCTION Quarter( d AS DATE , dwMonth := 1 AS DWORD ) AS DWORD
FUNCTION Quarter( dt AS DateTime , dwMonth := 1 AS DWORD ) AS DWORD
@Robert
in the VFP docs i found that {//} creates a empty date, but trying that with X# throws the error:
XS9002: Parser: unexpected CRLF, are you missing a token ?
I´ve tried it with my FP-DOS dinosaur and the result is:
Code: Select all
d = {//}
? Dtoc (d ) && " . . "
Karl-Heinz
- Attachments
-
[The extension viaef has been deactivated and can no longer be displayed.]
RAt() and ChrTran() functions
Karl Heinz,
For an empty date you can use NULL_DATE.
We'll see if we can parse that VFP format for an empty date as well in a future build.
Robert
For an empty date you can use NULL_DATE.
We'll see if we can parse that VFP format for an empty date as well in a future build.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
- kevclark64
- Posts: 127
- Joined: Thu Aug 15, 2019 7:30 pm
- Location: USA
RAt() and ChrTran() functions
FYI, in Foxpro you don't need the slashes for an empty date. The open and close curly brackets by themselves do the same thing.