An example of converting the hump string of a PHP interview question to an underline style. For example, if the hump string of a PHP interview question is converted into an underline style, when you see this problem, you can use ASCII code to handle it, I didn't want to use the omnipotent regular expression to convert the hump string of the PHP interview question to an underline style.
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:
$ 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 ).'
';
Answer 2:
The code is as follows:
Echo strtolower (preg_replace ('/((? <= [A-z]) (? = [A-Z])/',' _ ', $ str )).'
';
Then, in turn, how can I convert the underlined string into a camel (www.111cn.net) peak string?
The code is as follows:
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 ()
}
}
From: http://www.111cn.net/phper/php-cy/59093.htm
How can we convert string styles from camper to underline in java?
Public class transform {public static String trans (String str) {List record = new ArrayList (); for (int I = 0; I = 'A') {record. add (I); // records the location of each uppercase letter} record. remove (0); // The first one does not need to be underlined str = str. toLowerCase (); char [] charofstr = str. toCharArray (); String [] t = new String [record. size ()]; for (int I = 0; I
Php regular expression how to convert all spaces in a string into underscores
The simple code is as follows:
Preg_replace ('/[\ s]/', '_', $ content); // replace spaces, including spaces. if you have any questions, contact us ~
When the hacker saw this problem, he thought of using ASCII code to handle it. he didn't think about the omnipotent regular expression...