Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: prob regarding -strpos-
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
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 <[email protected]
> 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/