One Star

[resolved] [R] Aphanumic qunc

Hi forum
Is there a simply way to generate an alphanumeric sequence like this?
0000
0001
.....
9999
A000
A001
....
A999
B000
.....
Z999
AA00
AA01
.....
AA99
AB00
.....
AZ99
BA00
.....
ZZZZ
Regards
Alessandro
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] [R] Aphanumic qunc

Yes, you can generate alphanumeric sequence like A0001, A0002, ...

Do these,
1. Use Numeric->sequece (from 99990001, increment by 1)
2. Convert this field type to string using tConvertType
3. Use tReplace to replace 9999s with A.
It worked and I tested it.
Thanks,
Jagadish.
9 REPLIES
One Star

Re: [resolved] [R] Aphanumic qunc

Up.
I would like is to create a sequence > 9999 but I have only 4 digits.
Regards
Alessandro
Seven Stars

Re: [resolved] [R] Aphanumic qunc

If you're happy to use a more normal sequence (like hexadecimal but extended) it would be easier:
0000
0001
.....
0009
000A
000B
.....
000Z
0010
0011
.....
001Z
0020
.....
00ZZ
0100
.....
ZZZZ
But what exactly do you want to do with this sequence?
One Star

Re: [resolved] [R] Aphanumic qunc

Hi
Maybe a sequence like in your example it can be the solution.
How I can to do this?
It seems that the function "sequence" only works from 0 to 9 without alphabetic characters.
My sequence is a part of a code that I concatenate with other strings.
Regards
Alessandro
Seven Stars

Re: [resolved] [R] Aphanumic qunc

Create a user routine as follows (based on Numeric.sequence) but you can't control the start point or step. Note also that it loops back to "0000" if you exceed the maximum 1679615 values that can fit.
public class MyRoutines {

private static final java.util.Map<String, String> seq_Hash = new java.util.HashMap<String, String>();

public static String sequence(String seqName) {

String currentValue = "0000";
if (seq_Hash.containsKey(seqName)) {
currentValue = seq_Hash.get(seqName);
}
char[] valueArray = currentValue.toCharArray();
for (int position=3; position>=0; position--) {
if (valueArray < 'Z') {
if (valueArray == '9') {
valueArray = 'A';
} else {
valueArray++;
}
break;
} else {
valueArray = '0';
}
}
seq_Hash.put(seqName,String.valueOf(valueArray));
return String.valueOf(valueArray);
}
}
One Star

Re: [resolved] [R] Aphanumic qunc

Hi Alevy
I'm not sure to understand you code; you substitute the value 9 with A in certain position of the initial string.
But if in my sequence I have the number 10000 how it can transformed in A000?
Besides you say that you sequence have maximum 1679615 values.
If I use all the character from A to Z of the ASCII table on exclusion of the lower-case i can arrive just 736335=ZZZZ.
Regards
Alessandro
Seven Stars

Re: [resolved] [R] Aphanumic qunc

My post on 30 Sep shows the sequence my code constructs, where each digit cycles from 0 to 9 then A and on to Z i.e. 36 values for each digit. For example, 0010 in my sequence equates to 36 in decimal. Maximum sequence value is 36^4-1 for ZZZZ.
One Star

Re: [resolved] [R] Aphanumic qunc

Hi forum
I have developed a function that made a relation from the number to the ascii code.
I'm sure that it can to be optimized (all contributes are accepted)!!! :-)
I propose this:
Var.sMod = null;
int iNumSeq = 0;
int iN1 = 0;
int iN2 = 0;
int iN3 = 0;
int iN4 = 0;
String s1;
char sL1;
char sL2;
char sL3;
char sL4;
//Nell'assegnazione converto il valore string in char
iNumSeq = Numeric.sequence(context.sTipProd,0,1);
if (iNumSeq < 10000) {
Var.sMod = StringHandling.RIGHT("0000" + iNumSeq, 4);
} else if (iNumSeq > 9999 && iNumSeq < 36000) {
//Prelevo i caratteri in posizione 12
s1 = StringHandling.LEFT("" + iNumSeq, 2);
//Li converto nella lettera che andrò a sostituire
sL1 = (char) (Integer.parseInt(s1) + 55);
//Compongo la stringa alfa-numerica
Var.sMod = "" + sL1 + StringHandling.RIGHT("000" + iNumSeq, 3);
} else if (iNumSeq > 35999 && iNumSeq < 103600) {
//Definisco l'incremento del primo carattere
iN1 = (iNumSeq - 36000) / 2600;
sL1 = (char) (iN1 + 65);
//Definisco l'incremento del secondo carattere
iN2 = ((iNumSeq - 36000) / 100) - iN1 * 26;
sL2 = (char) (iN2 + 65);
//Compongo la stringa alfa-numerica
Var.sMod = "" + sL1 + sL2 + StringHandling.RIGHT("00" + iNumSeq, 2);
} else if (iNumSeq > 103599 && iNumSeq < 279360) {
//Definisco l'incremento del primo carattere
iN1 = (iNumSeq - 103600) / 6760;
sL1 = (char) (iN1 + 65);
//Definisco l'incremento del secondo carattere
iN2 = ((iNumSeq - 103600) / 260) - iN1 * 26;
sL2 = (char) (iN2 + 65);
//Definisco l'incremento del terzo carattere
iN3 = ((iNumSeq - 103600) / 10) - iN2 * 26 - iN1 * 676;
sL3 = (char) (iN3 + 65);
//Compongo la stringa alfa-numerica
Var.sMod = "" + sL1 + sL2 + sL3 + StringHandling.RIGHT("" + iNumSeq, 1);
} else if (iNumSeq > 279359 && iNumSeq < 736336) {
//Definisco l'incremento del primo carattere
iN1 = (iNumSeq - 279360) / 17576;
sL1 = (char) (iN1 + 65);
//Definisco l'incremento del secondo carattere
iN2 = ((iNumSeq - 279360) / 676) - iN1 * 26;
sL2 = (char) (iN2 + 65);
//Definisco l'incremento del terzo carattere
iN3 = ((iNumSeq - 279360) / 26) - iN1 * 676 - iN2 * 26;
sL3 = (char) (iN3 + 65);
//Definisco l'incremento del quarto carattere
iN4 = ((iNumSeq - 279360)) - iN1 * 17576 - iN2 * 676 - iN3 * 26;
sL4 = (char) (iN4 + 65);
//Compongo la stringa alfa-numerica
Var.sMod = "" + sL1 + sL2 + sL3 + sL4;
} else {
Var.sMod = "#out";
}

Regards
Alessandro
One Star

Re: [resolved] [R] Aphanumic qunc

Yes, you can generate alphanumeric sequence like A0001, A0002, ...

Do these,
1. Use Numeric->sequece (from 99990001, increment by 1)
2. Convert this field type to string using tConvertType
3. Use tReplace to replace 9999s with A.
It worked and I tested it.
Thanks,
Jagadish.
One Star

Re: [resolved] [R] Aphanumic qunc

Ok, but after Z9999 I want to have AA000 and to terminate the sequence with ZZZZZ.
I think that isn't possible with you solution...
Regards
Alessandro