Matching strings that appear in both lower and upper case (or are a combination of lower case and upper case letters)

送分小仙女□ 提交于 2019-12-25 07:48:02

问题


I am trying to find a word from a column in Stata that could appear in all caps or all lower case.

    foreach varlist_cust in "xyz" "XYZ" "XyZ" {


replace cus_tag = strpos(customer_name, "`varlist_cust'") if cus_tag==0

}

Is there a more efficient method of conducting this analysis? Maybe with the use of regular expressions?


回答1:


No need for regular expressions as Stata has a built in lower() function. See, for example

clear
input str9 customer_name
"Ander2Ed"
"sonu"
"abcXyZcba"
"XYZ"
"zXyZ"
end

gen cus_tag = strpos(lower(customer_name), "xyz")

Simply evaluate the customer_name variable as lowercase against the lowercase values you are looking for.

see help lower and help string functions for more.



来源:https://stackoverflow.com/questions/38921539/matching-strings-that-appear-in-both-lower-and-upper-case-or-are-a-combination

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!