Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: prob regarding -strpos-


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: prob regarding -strpos-
Date   Sat, 28 Jul 2012 14:40:26 +0100

This does indeed seem surprising but right now I can't check whether it's reproducible. In any case you would need to use different machinery (extended macro functions) to check for presence of a substring in strings longer than 244 characters given limits documented at -help limits- and in the manual.

Nick

On 27 Jul 2012, at 16:22, Pradipto Banerjee <pradipto.banerjee@adainvestments.com > wrote:

I have a code snippet that uses -strpos-, and works correctly within Stata GUI, but within an ado file doesn't seem to work. Within the Stata GUI, I tried

---
. local typelist "byte int long float double"
. forvalues i=1(1)244 {
.       local typelist "`typelist' str`i'"
. }
. local type = "int"
. local typegiven = strpos(`"`typelist'"', `"`type'"')
. display `"`type'"'
int
. display `typegiven'
6
---

Within the ado file, I wrote

---
program define myfunc, byable(onecall) sortpreserve

gettoken type 0 : 0, parse(" ")
local typelist "byte int long float double"
forvalues i=1(1)244 {
       local typelist "`typelist' str`i'"
}
local typegiven = strpos(`"`typelist'"', `"`type'"')
display `"`type'"'
display `typegiven'

end
---

When I ran the ado file in the Stata GUI, it returns the first display lines correctly, but doesn't seem to return anything from the second display line (or may be returns a blank.

---
. myfunc byte test
byte

---

Can someone help me with this code?
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index