Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Capitalize String

Given a string, capitalize it. By capitalization I mean conTeNT-lENgth changes to Content-Length. In the example I showed the string with 2 words with - as the word boundary. However I expect you to write the code for the string containing any number of words separated by a single character as the boundary. This boundary may change across the string.

Conditions

  1. using regular expressions is not allowed.
  2. there could be any number of words in a sentence(string).
  3. each word will consist of English letters[a-zA-Z] of any case.
  4. different words in the sentence will be separated by a single character. This character will only be any one of -, ., , /, &, #. You can safely assume that sentence will not contain any other character except the mentioned ones.
  5. word boundaries should be preserved in the output.
  6. shortest code wins.

For example your program should output Begin/With.Type&Content for BeGin/wITH.tyPE&conTeNt.

Some test cases:
 "aGeNT ACcEpT/LEngTh-tYPe USeR raNgE.TyPe" 
 "type&AgeNt/CC/COnteNt lEnGth#acCePT/AgeNt.RAnGe-Cc/contEnt/cODe" 
 "cc/rEspoNCe.lEngtH#tYpE-witH&UsEr/bEgIN&uSer.AGEnT&begIn/aCCEPt/Cc" 
 "lENgTH#USeR.tYpE/BeGiN&LENGth tYpe/ACCEpt#rANge/codE&AnD-ACCepT/ConTenT" 
 "contENT/ACcEpT" 
 "BeGin/wITH.tyPE&conTeNt"
 "Code.cc#User.lenGTh-USer-AND&tyPE TypE&leNgtH.tYPe usER.UseR&with" 
 "RaNgE&COnTeNT WITh CoNTENT-TypE tyPe"
 "BEgin COdE#uSeR#aGeNt.USeR"
 "TypE LENGth"

Answer*

Draft saved
Draft discarded
Cancel
1
  • \$\begingroup\$ That's pretty cool :-) \$\endgroup\$ Commented Mar 30, 2016 at 9:12

AltStyle によって変換されたページ (->オリジナル) /