A repost - Permuting SPACES within a String of words

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Hari Prasadh (excel_hariNOSPAM_at_hotSPAREMEmail.com)
Date: 02/03/05


Date: Thu, 3 Feb 2005 20:30:33 +0530

Hi,

I posted this problem around 3-4 days back.....I have tried to paraphrase
the problem in a probably simpler way below.

I want to generate permutations of a string made up of 2 or more words in
such a way that I get outputs :

a) where there is no space between any of the words in the string
b) Where there is only one space between any 2 words in the string.
c) where there is a single space between some of the letters in the string
but rest words dont have any space between them. And do this process for all
possible permutations.

I have got solutions to a) and b) by swiping from previous posts. ( Split
array method )

It's the c) which is..

For example if I have a string in Cells(1,1) having the value -- I went to
Paris --

the answer for a) will be -- IwenttoParis --
the answer for b) will be -- I went to Paris -- Basically, b) will be same
as the original string.

the answer(s) for c) would be
i) Iwentto Paris
ii) I wenttoParis
iii) Iwent toParis
iv) Iwent to Paris
v) I went toParis
vi) I wentto Paris

Explanation - of part c) :
In parts i) and ii) 3 of the words in the string have been combined together
and the lone word is separated by a single space.

 In part iii) 2 sets of adjacent words have been combined together and there
is a single space between these 2 set.

In parts iv), v) and vi) ONLY one set of adjacent words have been combined
together and there is a single space between any 2 words.

How to effect the above combinations... in view of the fact that number of
words in the string (Cells(1,1)) would be variable.

Thanks a lot,
Hari
India



Relevant Pages

  • Re: A repost - Permuting SPACES within a String of words
    ... Then you should check for empty cells array ... Use ubound to find out how many cells your array contains ... > a) where there is no space between any of the words in the string ... > together and the lone word is separated by a single space. ...
    (microsoft.public.excel.programming)
  • Re: RegularExpressionValidator expression help
    ... Take a look at first expression ... ("\s" means a single space, and should be used in .NET) ... no way to check by regex if given postal code is related to given ... the string is correct and string has proper format, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Remove spaces in CSV file using VB6
    ... using a Byte array instead of a string unless speed is critical (which I ... I am pretty sure that the OP wants to keep the single space between ...
    (microsoft.public.vb.general.discussion)
  • Re: Comparing 2 strings for matches in any order
    ... > single space delimiter). ... I need to compare to Column A row 2 and so forth. ... > Then the whole process repeats, matching Column B's bear to the array ... > determine that there was a positive match made for that string in ...
    (microsoft.public.access.modulesdaovba)
  • Re: Help needed with algorithm in C++
    ... >>permutations, the number you generate is huge! ... >>aaaabccddd I wrote a little test which generated 257680 unique ... discovered that if you permute a string of a As, b Bs, c Cs, and d Ds, ... >>each position through all 3 symbols using recursion. ...
    (comp.programming)