Generating folders using textboxes [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Hello experts, I have to generate series of folders from a TextBox into specified location.I am having two textboxes to specify the limit of folders(say 30 folders).The problem am facing is that the folder names that i will be providing are alpha-numeric(say 121cs3h101) .
How to set limit when i provide an alpha-numeric values?
(For example: i provide textbox1=12cs3h101 and textbox2=12cs3h131 , i need the series limit to be generated). I am working with visual studio 2013 in c# windows form application. Thanks in advance.

ok I will try to give you a lead.
To parse a string or find specific characters one can use RegEx.Match or a simler method called String.Split. In both cases you have to be aware how your string is structured and how it can vary. The limits of variation are very important.
If as you say the beginning is always"12cs3h" you can either split the string at the character 'h'.
string[] sa = s.Split('h');
Or you can even use the index of 'h' (since the length seems to be fixed) and take the rest of the string to get the numbers.
int index = s.IndexOf('h');
The rest is up to you, ... convert, enumerate and so on.
EDIT: There is a nice method that does the enumeration job for you: Enumerable.Range Good luck

Related

Generate skipable list based on chars [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am very sure that there is a technical term for this problem, but unfortunately I do not know it.
I have an alphabetical charset and the requirement is to create the combination of all the chars with a maximum length
The idea is (sample):
Generate a collection of A, AA, AAA, AAAA, AAAAA, AAAAAA
Next: A, AB, ABA, ABAA, ABAAA
Next A, AB, ABB, ABBA, ABBAA
The reason:
We have to query an API that delivers search results.
But if I don't get search hits from the API on AAA, I don't need to search for AAAA anymore, because it can't get search hits either. I can then move on to AAB.
The question:
My problem is that I'm not sure how the code has to be built to achieve this goal. I lack the structural approach.
I've already tried nested loops, but unfortunately I don't get the result.
I also used Combination Libraries, but they focus on other problems.
Many thanks for hints!
What you're looking for is a particular data structure called a Tree, but probably more specifically in your case, a Trie.
Trie data structures are commonly used in things like Autocomplete. With the image below, if someone typed "te", I can traverse the Trie and see what options would come after that (tea, ted, ten).
It looks like this would also fit your use case from what I can tell.

how do i display how many digits the number has? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Currently very new to C# and coding , so i will be more than happy if someone will explain me how to display how many digits the number has. For example the number 12345 has 5 digits.the main theme in the class is while loops so the answer probably need to contain while loop.TY
You can either use this
Math.Abs(myint).ToString().Length
and if you absolutely must use a while loop then
number = Math.Abs(number);
int length = 1;
while ((number /= 10) >= 1)
length++;
To test code
string.Trim().Replace("-","").Length
so if you have a number you should make it a string first using ToString()
The Length returns the number of characters that you hold within your string minus your white spaces (Because of the Trim()),i don't see why you would want to use the while loop in the first place.
Edit : if you have a minus number the .Replace() will take care of that.

What does string.IndexOf do? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm working through string manipulation, where I need to find characters or copy some part of the string that the user has input and divide it to 3 different areas. I'm not asking anything here about code, I'll do it myself, but I was searching in the documentation that Microsoft provide about the IndexOf method and its 8 overloads and I can't really understand how to apply it. I simply can't understand what it is supposed to do.
Returns the first appearance of a specified char.
For example
string x = "Hello World";
x.indexOf("W");
it will return 6 (0 based count).
The overloads let you choose for example, where you want to start searching.. like
x.indexOf("W", 7); it will return -1 because W is at position 6 so if starts at 7 it won't find any.
I hope this helps ! the best way is to play with it
This also works with arrays.
I believe the MSDN explanation is pretty clear.
For example:
string something = "something";
int indexOfT = something.IndexOf("t"); // => returns 4
Reports the zero-based index of the first occurrence of the specified string in this instance.
So if "t" is in the fifth position of "something", 4 would be it's zero-based index.

C# - How to assign different lines of File.ReadAllText to individual variables? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
What I've got is a text file with some (hypothetical) students and their attendance.
Looks like this:
Stud1
LOOOALLOOAAL
Stud2
OOOOOOOAOOOO
Stud3
LLLLOOOOALLA
So what I want to do, is assign say Stud1 to show Stud1: LOOOALLOOAAL etc etc.
Any ideas?
actually your post is kind of "unclear" to readers but I did get your point regarding reading lines from text to variables
I suggest you use File.ReadAllLines, then format your text with each values separated per line
so it goes like this
Source.txt
LOOOALLOOAAL
OOOOOOOAOOOO
LLLLOOOOALLA
then your line of code will be
string[] students = File.ReadAllLines("Source.txt");
thus the values would be
students[0] = LOOOALLOOAAL
students[1] = OOOOOOOAOOOO
students[2] = LLLLOOOOALLA
the code File.ReadAllLines() gets every line of text from your source file until it reaches the endline and stores it into an array of string. if you needed your values for calculations, then you'll need to parse such values
I just showed you how to get values from text to variables. how you show them as output will be on you.

possible test cases for testing a method [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
In one of the interview I was asked to test a method. The details are mentioned below. Though I could answer , still they were expecting some more test cases. Am I missing any scenarios here ?
string concatenatefunc(strin1,string2).
{
//returns concatenation
}
This method accepts two string parameters and returns the concatenation. No other details are mentioned. I need to test this method and i have written below scenarios/unit test cases:
1.Pass empty parameters and see empty string is returned
2.Pass valid non empty strings and see the string returned is correct or not.
3.Pass the special characters in the both the parameters and test the response.
4.Pass integers and test the response.
5.pass large strings(not sure what we can give as the max length) and test the response.
....
Anything to add here?
You're not testing for null parameters.
Test for multi language support. An area that many developers fail to test which can give a guy like me problems. I have the danish character 'ΓΈ' in my name. This has been a problem in my web based interactions with several VERY BIG companies including software companies, preventing me from logins, accounts, payments etc.
Number 5 will really depend on the size of available resources so testing that might be problematic.
You could add tests for either parameter being empty and see if the non-empty parameter is returned
Same for Passing integers, test if either parameter is integer
Then you could start mixing them empty/integer, non-empty/integer, etc. and reverse

Categories

Resources