Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: String comparisons in Mata


From   "German Rodriguez" <[email protected]>
To   <[email protected]>
Subject   st: String comparisons in Mata
Date   Sun, 29 Jan 2006 16:07:55 -0500

Dear list,

A mata question: Why is "a" converted to uppercase == "A" (and also <= "A")
but NOT >= "A"? 

. mata: strupper("a") >= "A"
  0

. mata: strupper("a") == "A"
  1

I was trying to determine if a string scalar was a letter and the obvious 

scalar function isLetter(string scalar s) {
	S = strupper(s)
	return (S >= "A" & S <= "Z")
}

didn't work with "a" (although it works with "b" because strupper("b") >=
"A" is true). I got around the problem using the slightly more cryptic

scalar function isLetter(string scalar s) {
	n = ascii(strupper(s))
	return (n >= 65 & n <= 90)
}

but I am curious. 

Cheers,
German

P.S. My Stata *is* up-to-date. I am running 9.1 born 20 Jan 2006

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index