Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am trying to make an array that will add every string possible for this string:
C#
list.Add(new String[] {});


What I have tried:

I have tried puting * and ** for the string but non work.
list.Add(new String[] {**});
list.Add(new String[] {*});
Posted
Updated 16-Mar-16 8:14am
Comments
LLLLGGGG 16-Mar-16 14:14pm    
I'm not sure I have understood the question: would you like to add every possible combination of characters into that list?
Richard Deeming 16-Mar-16 14:59pm    
Think about what you're asking. A string is a sequence of chars, each of which can hold 65,536 possible values.

There would be 65,536 possible 1-character strings.
For two characters, 4,294,967,296 possible strings.
For three characters, 281,474,976,710,656 possible strings.
And so on.

Strings can be up to 2,147,483,647 characters long.

Even if you used every single computer in the world, you wouldn't be able to store every possible string!
Matt T Heffron 16-Mar-16 17:01pm    
The first question this brings to mind is:
Why?
What are you expecting to do with these strings?
What is the actual problem you are trying to solve?
johannesnestler 17-Mar-16 10:30am    
that sounds like absolute nonsense - better explain us what you want to achieve - so we can try to help you with your real problem (the problem that lead you to an "idea" like this). In your example it looks like you want to construct a list of lists of all "possible" (????) strings, so not only "ALL" but many lists with "all possible" strings????

1 solution

For starters, you would have to define an upper length for strings, otherwise the amount of strings would be endless and you would run out of memory.

And, assuming you didn't mean to add * and ** as two strings but intended to force an automatic population of your array with all possible strings: There's no such inbuilt functionality. You will have to implement the method/algorithm for that yourself.

And you probably also want to limit the character set of which your strings can be composed unless you want strings including non-printable control characters.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900