March 7th, 2013, 12:54 AM
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, 01: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, 01: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, 01: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, 01: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.