0

i have a function in try catch and final block i know that function will always use finally block of code but here it should add character i no want to use while loop

 string increse_me ; public void brut() { string[] small = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; string[] cap = new string [] {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; string[] num = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}; string[] spcl = new string[] { "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "`", ">", "<", "+" }; if( textbox1.Text == increase_me) { messagebox.show("matched") } catch (exception ex) { } finally { brut(); //here i have to call function again with increase letter as start from "a"it add next to it } } 

Now how to make a function that use string declared increase_me for the first time and also increase its value when finally fails from second arrray and so on to 26 max digit

6
  • 1
    If you want to write a method that moves the string the next permutation with each call, you'll have to check the last character of the current string (e.g. "!" of "asd123B!"), and implement rollover ("B+" becomes "Ca"). That's doable, but I hope you don't expect us to write that method for you. Commented Jan 6, 2016 at 21:45
  • 3
    You are aware that this will have stack overflow problems because of an infinite recursion right? Commented Jan 6, 2016 at 21:45
  • 1
    It is hard to tell what you are asking, but I think you are just looking for something similar to "Generate all combinations for a list of strings" Commented Jan 6, 2016 at 21:45
  • 1
    Ever look at the String.Join method? msdn.microsoft.com/en-us/library/57a79xd0(v=vs.110).aspx Commented Jan 6, 2016 at 21:48
  • If the intent is to add the strings from each of the arrays of small, cap, num and spcl to the increse_me, one could just use the Join method on each array to add into the increase_me assuming a block transaction is desired. If there is repetition of doing each string one by one then a loop is likely to be required unless one wants to write some really ugly recursive function to pass in the ever shrinking array to add the values across which would be another route one could take. Commented Jan 6, 2016 at 21:51

1 Answer 1

0

On an intuitive level, you could just pass in an array and the string and return an updated string with the first element appended:

string stringUpdate(string update, string[] toAdd) { if (toAdd!=null && toAdd.length>0) { return update+toAdd[0]; } return update; } 

This would then make brut() have to be smart about what to pass into the function so that it isn't passing in empty arrays though it would just return the first string if that is the case. Course this is just part of the overall solution as I would suspect a regular expression to be a much easier solution to have here but that wasn't asked.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.