![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
|
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... FROM (SELECT DISTINCT ID, this, that FROM table_name WHERE conditions) a, (SELECT DISTINCT ID, this, that FROM table_name WHERE conditions) b, (SELECT DISTINCT ID, this, that FROM table_name WHERE conditions) c WHERE a.ID = b.ID AND a.ID = c.ID; Thank you in advance. |
|
|
|
|
|
#2 |
|
Java Developer
|
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(); } |
|
|
|
|
|
#3 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3
![]() |
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)
{
String s = ('a' + num / 26);
s += ('a' + num % 26);
return s;
} |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Jun 2005
Posts: 92
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#5 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3
![]() |
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...
|
|
|
|
|
|
#6 |
|
Newbie
|
Thanks guys, here's what I went with:
private static String makeStr(int num) {
int r,s=0;
r = ('a' + num / 26);
s = ('a' + num % 26);
String s1 = new Character((char)r).toString();
String s2 = new Character((char)s).toString();
return s1+s2;
} |
|
|
|
|
|
#7 |
|
Expert Programmer
|
You can simplify this function as follows, such that you don't declare unnecessary variables.
private static String makeStr(int num) {
String s1 = String.valueOf((char)('a' + num / 26));
String s2 = String.valueOf((char)('a' + num % 26));
return s1 + s2;
} |
|
|
|
|
|
#8 | |
|
Newbie
|
Quote:
|
|
|
|
|
|
|
#9 | |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3
![]() |
Quote:
private static String makeStr(int num) {
return String.valueOf((char)('a' + num / 26)) + String.valueOf((char)('a' + num % 26));
} |
|
|
|
|
|
|
#10 | |
|
Newbie
|
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|