![]() |
generating character sequence
Does anybody know if there's a Java class out there to automatically generate character sequences (i.e., a, b, c, d, e, ..., aa, ab, ac, ...)? I'm going to be generating some SQL statements which could possibly get quite long, depending on the user input, which would be in the form of:
:
SELECT a.ID, a.this, a.that, b.this, b.that, c.this, c.that, etc...Thank you in advance. |
i have got a function "parsetext"
this function gets a string; devides it into tokens; replace tokens with the specified data; and create the required pattern... this function is part of project "PageDown" on SourceForge.net in a source file "frmWebDataS.java" you may refer this function to generate the sequence which you require.. private void ParseText() { ParsedData.removeAllElements(); int StaticText=0; int TagText=0; Vector<String> tmpTokentext=new Vector<String>(); StringTokenizer begintokens = new StringTokenizer(txtDownExp.getText(),"<"); while (begintokens.hasMoreTokens()) { tmpTokentext.add(begintokens.nextToken()); } if (tmpTokentext.size()==0) return; boolean FirstIsToken=tmpTokentext.get(0).startsWith("<"); for (int i=0;i<tmpTokentext.size();i++ ) { if (!FirstIsToken && i==0) { ParsedData.add(new ParsedText(tmpTokentext.get(i),null)); StaticText++; continue; } StringTokenizer endtokens = new StringTokenizer(tmpTokentext.get(i),">"); if (endtokens.countTokens()>2) { MainApp.LogWrite(frmName , "Parsing error, too many closing (>) tag..."); } ParsedData.add(new ParsedText(endtokens.nextToken(),new frmTagItem(MainApp))); TagText++; //TokenText.add(endtokens.nextToken()); if (endtokens.countTokens()>0) { ParsedData.add(new ParsedText(endtokens.nextToken(),null));; StaticText++; } } MainApp.LogWrite(frmName , "Parsing done (Text: "+StaticText+", Tag: "+TagText+")"); UpdateTagView(); } |
I don't know of anything to specifically generate sequences like that, but you could probably come up with your own fairly easy. Afterall, it's just like using base-26 numbering, without any arabic numerals, i.e.
:
String makeStr(int num) |
Jimbo, I don't think that works, unless i'm misunderstaning what it is supposed to do. When I put 25 in for num, I get "az", and the 25th one should be 'y', which is 27 away from "az".
OP: You may consider doing it like you would do a time converter. Given seconds convert to the correct number of hours, minutes, and seconds. These situations appear to me to be very similar. |
My code would do everything with 2 letters (you could add a condition for if the original value was less than 26). That said, the z was correct if you start counting from 0, as most programmers tend to do. Perhaps I should have commented that...
|
Thanks guys, here's what I went with:
:
private static String makeStr(int num) { |
You can simplify this function as follows, such that you don't declare unnecessary variables.
:
private static String makeStr(int num) { |
Quote:
|
Quote:
:
private static String makeStr(int num) { |
Quote:
|
| All times are GMT -5. The time now is 8:04 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC