Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. string concatenation with all possibilities

string concatenation with all possibilities

Scheduled Pinned Locked Moved C#
data-structures
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sethupathiram
    wrote on last edited by
    #1

    Hi All, string pattren = " INC | TRUST | COMPANY | 401K "; string[] ArrPattern = pattren.Split('|'); above the string array i need to concatenate all the posibilities like below output, ex: INC PLAN COMPANY 401K INC PLAN COMPANY empty INC PLAN empty 401k INC PLAN empty empty INC empty COMPANY 401k INC empty empty 401k INC empty empty empty empty PLAN COMPANY 401k ... ... ... like these 16 combination.... please share your ideas its very urgent for me... Regards, Ram

    P S P Richard DeemingR A 5 Replies Last reply
    0
    • S sethupathiram

      Hi All, string pattren = " INC | TRUST | COMPANY | 401K "; string[] ArrPattern = pattren.Split('|'); above the string array i need to concatenate all the posibilities like below output, ex: INC PLAN COMPANY 401K INC PLAN COMPANY empty INC PLAN empty 401k INC PLAN empty empty INC empty COMPANY 401k INC empty empty 401k INC empty empty empty empty PLAN COMPANY 401k ... ... ... like these 16 combination.... please share your ideas its very urgent for me... Regards, Ram

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      sethupathiram wrote:

      please share your ideas its very urgent for me

      So what have you got so far? What code have you written? Which part is causing you a problem?

      I was brought up to respect my elders. I don't respect many people nowadays.
      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

      1 Reply Last reply
      0
      • S sethupathiram

        Hi All, string pattren = " INC | TRUST | COMPANY | 401K "; string[] ArrPattern = pattren.Split('|'); above the string array i need to concatenate all the posibilities like below output, ex: INC PLAN COMPANY 401K INC PLAN COMPANY empty INC PLAN empty 401k INC PLAN empty empty INC empty COMPANY 401k INC empty empty 401k INC empty empty empty empty PLAN COMPANY 401k ... ... ... like these 16 combination.... please share your ideas its very urgent for me... Regards, Ram

        S Offline
        S Offline
        Simon_Whale
        wrote on last edited by
        #3

        Have a look at some of these and see what fits your needs best google: c# producing permutations of an array[^]

        Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

        1 Reply Last reply
        0
        • S sethupathiram

          Hi All, string pattren = " INC | TRUST | COMPANY | 401K "; string[] ArrPattern = pattren.Split('|'); above the string array i need to concatenate all the posibilities like below output, ex: INC PLAN COMPANY 401K INC PLAN COMPANY empty INC PLAN empty 401k INC PLAN empty empty INC empty COMPANY 401k INC empty empty 401k INC empty empty empty empty PLAN COMPANY 401k ... ... ... like these 16 combination.... please share your ideas its very urgent for me... Regards, Ram

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          This might help: Non-recursive Permutations and Combinations[^]

          1 Reply Last reply
          0
          • S sethupathiram

            Hi All, string pattren = " INC | TRUST | COMPANY | 401K "; string[] ArrPattern = pattren.Split('|'); above the string array i need to concatenate all the posibilities like below output, ex: INC PLAN COMPANY 401K INC PLAN COMPANY empty INC PLAN empty 401k INC PLAN empty empty INC empty COMPANY 401k INC empty empty 401k INC empty empty empty empty PLAN COMPANY 401k ... ... ... like these 16 combination.... please share your ideas its very urgent for me... Regards, Ram

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            Something like this should work:

            static IEnumerable<T[]> BuildCombinations<T>(T[] input)
            {
            int length = input.Length;
            int max = checked(1 << length);

            // Skip the first item, which would be completely empty.
            // (If you want this item, start at zero.)

            for (int combination = 1; combination < max; combination++)
            {
            var current = new T[length];

              for (int index = 0, bit = 1; index < length; index++, bit <<= 1)
              {
                 if ((combination & bit) != 0)
                 {
                    current\[index\] = input\[index\];
                 }
              }
            
              yield return current;
            

            }
            }

            ...
            string pattern = " INC | TRUST | COMPANY | 401K ";
            string[] ArrPattern = pattern.Split('|');
            List<string[]> allCombinations = BuildCombinations(ArrPattern);


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            1 Reply Last reply
            0
            • S sethupathiram

              Hi All, string pattren = " INC | TRUST | COMPANY | 401K "; string[] ArrPattern = pattren.Split('|'); above the string array i need to concatenate all the posibilities like below output, ex: INC PLAN COMPANY 401K INC PLAN COMPANY empty INC PLAN empty 401k INC PLAN empty empty INC empty COMPANY 401k INC empty empty 401k INC empty empty empty empty PLAN COMPANY 401k ... ... ... like these 16 combination.... please share your ideas its very urgent for me... Regards, Ram

              A Offline
              A Offline
              Anna King
              wrote on last edited by
              #6

              I don't find any other better combinations for it, all the BEST possibilities are mentioned in your thread itself.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups