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

前端 未结 13 709
别跟我提以往
别跟我提以往 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 15:54

    (defn parse-int [s]
      (Integer. (re-find #"[0-9]*" s)))
    
    user> (parse-int "10px")
    10
    user> (parse-int "10")
    10
    

提交回复
热议问题