March 6th, 2013, 11:54 PM
String manipulation help
I need a way to take a string "ThisString" find the occurrences of any uppercase letters and add a space " " between the last lowercase letter and the uppercase letter. IE:
"ThisString" to "This String"
"AnotherStringHere" to "Another String Here"
any help would be appreciated.
March 7th, 2013, 12:28 AM
Finds a capital letter in the middle of a "word" and sticks a space in front of it.
$new = preg_replace('/\B[A-Z]/', ' $1', $old);
March 7th, 2013, 12:39 AM
That actually replaced the uppercase with a blank. It didn't put a space in front of the uppercase. But at least it did do it only where there was an uppercase.
March 7th, 2013, 12:43 AM
I changed my mind a couple times before posting what I did. It's kinda a hybrid.
$new = preg_replace('/\B[A-Z]/', ' $0', $old);
March 7th, 2013, 12:50 AM
Way to kewl!
You should have seen some of the gyrations that I was trying to do to manipulate the string. Nothing was working, and wham, you give me a quick (short) single line that did it!
Thank you so very much.