In Clojure how can I convert a String to a number?

前端 未结 13 697
别跟我提以往
别跟我提以往 2020-12-12 15:34

I have various strings, some like \"45\", some like \"45px\". How how I convert both of these to the number 45?

13条回答
  •  一个人的身影
    2020-12-12 16:01

    AFAIK there's no standard solution for your problem. I think something like the following, which uses clojure.contrib.str-utils2/replace, should help:

    (defn str2int [txt]
      (Integer/parseInt (replace txt #"[a-zA-Z]" "")))
    

提交回复
热议问题