When I saw this problem, I thought of using ASCII code to handle it. I didn't think about it as a universal regular expression. Okay, let's take a look at the answer:
Answer 1:
The code is as follows: |
Copy code |
$ Str = 'openapi '; $ Length = mb_strlen ($ str ); $ New = ''; For ($ I = 0; $ I <$ length; $ I ++) { $ Num = ord ($ str [$ I]); $ Pre = ord ($ str [$ I-1]); $ New. = ($ I! = 0 & ($ num >=65 & $ num <= 90) & ($ pre >=97 & $ pre <= 122 ))? "_ {$ Str [$ I]}": $ str [$ I]; } Www.111cn.net Echo strtolower ($ new). '<br> '; |
Answer 2:
The code is as follows: |
Copy code |
Echo strtolower (preg_replace ('/((? <= [A-z]) (? = [A-Z])/',' _ ', $ str).' <br> '; |
In turn, how does one convert an underscore to a camper string?
The code is as follows: |
Copy code |
F = new File ("d:/temp/t.txt ") If (f. exists ()){ F. eachLine {line-> Line = line. trim () String [] elems = line. split ('_') For (int I = 0; I <elems. length; I ++ ){ Elems [I] = elems [I]. toLowerCase () If (I! = 0 ){ String elem = elems [I] Char first = elem [0] as char Elems [I] = "" + (char) (first-32) + elem. substring (1) } } Println elems. join () } } |