James Bach has a tool he created for generating a string that counts its own length so you can identify how many characters a UI text field can receive. If you go to http://ift.tt/1wWTreB you can download his PerlClip code and run the counterstring method. Essentially, if you type in "counterstring 10", it would output "*3*5*7*10*" which is a ten-character long string, such that each asterisk is at a position in the string equal to the number that precedes it.
counterstring 12 would produce *3*5*7*9*12*
counterstring 13 would produce *3*5*7*10*13*
counterstring 14 would produce 2*4*6*8*11*14*
counterstring 15 would produce *3*5*7*9*12*15*
counterstring 16 would produce *3*5*7*10*13*16*
counterstring 17 would produce 2*4*6*8*11*14*17* etc...
How would I go about generating this code in C#? The counterstring always ends in an asterisk, so I figured I'd better use a for loop and decrement to the beginning; however, I can't even wrap my head around where to start.
public static string Counterstring(int num)
{
//*3*5*7*9*12*
//*3*5*7*10*13*
//2*4*6*8*11*14*
//*3*5*7*9*12*15*
//*3*5*7*10*13*16*
//2*4*6*8*11*14*17*
string textNumberString = "";
for (int i = num; i > 0; i--)
{
}
return textNumberString;
}
Thank you!
Aucun commentaire:
Enregistrer un commentaire