Message Boards Message Boards

Easy way to split CamelCase ?

Is there an easier way to split CamelCase? Perhaps anything builtin to avoid RegularExpression?

StringJoin[StringSplit["AntiqueWhite and LavenderBlush", RegularExpression["([a-z])([A-Z])"] -> "$1 $2"]]

Out[]= "Antique White and Lavender Blush"

POSTED BY: Vitaliy Kaurov

Well, this certainly works--though it is the same as yours but using a StringExpression instead of a RegularExperssion:

StringReplace["AntiqueWhite and LavenderBlush",
 x : CharacterRange["a", "z"] ~~ y : CharacterRange["A", "Z"] :> 
  x <> " " <> y]

And like yours, it does not check if the new separated words are actually words...

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract