Convert wholly capitalized words in a string into uppercase first only
Hi all,
I have a string in which I want to find any wholly uppercase word (e.g. TEST ) and then convert it into ( Test ) .
I can't code it , headache after many trials !
Can someone help ?
Hint : I can't use explode(" ",$string ) to convert it into an array to itreate it .. Because the string words are not only separated by spaces , but some words are separated by \n
Given a string S1, replace "\n", using str_replace(), with a special token " xx--99---2 ", where the special token has both a leading and trailing blank, to give string S2. Now explode S2, and do your operation on the exploded result. but be careful that the operations done will not affect the special token. Subsequently implode the new results to give the string S3. Finally replace the special token using str_replace(), with "\n" to give S4, and your task is complete.
Knowledge is that which can be shown to be the case, and Intelligence is the method one uses to deploy the demonstration of what is the case, everything else is Information.
(Any time you want to manipulate a string, it's always a good idea to start here first. )
PS: If for some reason you wanted to go the explode() route, instead use preg_split().
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Hmm...think I missed the part about only all-caps words. That looks like a good solution, though there might be some edge cases that could be problematic, such as the name "MACTAVISH", which should normally be spelled "MacTavish". (And we won't even try to figure out to do with "Dupont", "DuPont", "duPont", "Du Pont", or "du Pont". )
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks