I implemented this in "one" line of VB:
Dim outText = Regex.Replace(inText, _
"\b([a-zA-z])([a-zA-Z]+)([a-zA-Z])\b", _
Function(g) (g.Groups(1).Value & String.Join("", _
(g.Groups(2).Value.ToCharArray.OrderBy( _
Function(c) (Rnd(1))) _
)) & _
g.Groups(3).Value))
A better solution would provide a 'more correct' Function
for OrderBy
that would return the same value for a particular character in a string, but in this case, simply setting the Rnd
seed would do to get (somewhat) repeatable results.
(Note that setting the Function
to be directly dependent upon the c
provided means all internal characters are reordered according to some random ordering, so all internal repeated letters are always grouped together in the scrambled words.)
An example of the output:
(Note that sttenig the Fictunon
to be drcteily dpeednent uopn
the c
previodd mnaes all inratnel cthcearras are roeerredd
aindorccg to smoe ronadm oidrreng, so all ietnnarl reteaepd
ltteers are awayls guorped tgtheoer in the srlmceabd wodrs.)