• David Waugh
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 2
    Replies

Hi,

 

Banks are really old-fashioned in the way they handle text data in files sent through even the latest standards-managing IT systems.  In SEPA, for example, they still handle text in their own charset which is not Unicode, more similar to old ASCII or even EBCDIC :(

 

In the US, its not a big problem, but in European and Asian countries, this is mega-important.

 

In Java, the Normalize and Pattern classes are great for this : Unicode text can be normalized down to ASCII in 2 or 3 instructions. In Apex, things are *very* long.

 

This is the normalization I go through today :

 

private String clean(String in) {
    //String minmaj = "ÀÂÄÇÉÈÊËÎÏÛÜÔÖaàâäbcçdeéèêëfghiîïjklmnoôöpqrstuùûüvwxyz";        
    //String maj    = "AAACEEEEIIUUOOAAAABCCDEEEEEFGHIIIJKLMNOOOPQRSTUUUUVWXYZ";
    String acc = 'ÀÂÄÇÉÈÊËÎÏÌÛÜÙÔÖÒÑ' + '°()§<>%^¨*$€£`#,;./?!+=_@"' + '\'';        // et Œ, Æ, &; 
    String maj = 'AAACEEEEIIIUUUOOON' + '                          ' + ' ';
    
    String out = '';                 
    for (Integer i = 0 ; i < in.length() ; i++) {
        String car = in.substring(i, i+1);
        Integer idx = acc.indexOf(car);
        if (idx != -1){
            out += maj.substring(idx, idx+1);
        } else if (car == 'Œ') {
            out += 'OE';
        } else if (car == '&') {
            out += 'ET';
        } else if (car == 'Æ') {
            out += 'AE';
        } else {
            out += car;
        }
    }
    
    return out;
}

 

Remember, this is to produce files where alignment is important, so I can't just replace Æ with AE without fixing the padding instructions (elsewhere).

 

This method uses too many instructions : has anyone got a better way of doing it, still in APEX ?

 

TIA,

Rup

If you don't want to hard code your recordtype ids in a SOQL query, here is an example on how to query using the record type name:

 

Select id, name,  type, RecordType.Name, AMOUNT, closedate, stagename

FROM Opportunity
WHERE recordtypeid in (Select Id From RecordType where sobjecttype = 'Opportunity' and name in ('Daily Open Quote Record Type', 'Prospect Record Type'))
limit 100

Hi,

 

Banks are really old-fashioned in the way they handle text data in files sent through even the latest standards-managing IT systems.  In SEPA, for example, they still handle text in their own charset which is not Unicode, more similar to old ASCII or even EBCDIC :(

 

In the US, its not a big problem, but in European and Asian countries, this is mega-important.

 

In Java, the Normalize and Pattern classes are great for this : Unicode text can be normalized down to ASCII in 2 or 3 instructions. In Apex, things are *very* long.

 

This is the normalization I go through today :

 

private String clean(String in) {
    //String minmaj = "ÀÂÄÇÉÈÊËÎÏÛÜÔÖaàâäbcçdeéèêëfghiîïjklmnoôöpqrstuùûüvwxyz";        
    //String maj    = "AAACEEEEIIUUOOAAAABCCDEEEEEFGHIIIJKLMNOOOPQRSTUUUUVWXYZ";
    String acc = 'ÀÂÄÇÉÈÊËÎÏÌÛÜÙÔÖÒÑ' + '°()§<>%^¨*$€£`#,;./?!+=_@"' + '\'';        // et Œ, Æ, &; 
    String maj = 'AAACEEEEIIIUUUOOON' + '                          ' + ' ';
    
    String out = '';                 
    for (Integer i = 0 ; i < in.length() ; i++) {
        String car = in.substring(i, i+1);
        Integer idx = acc.indexOf(car);
        if (idx != -1){
            out += maj.substring(idx, idx+1);
        } else if (car == 'Œ') {
            out += 'OE';
        } else if (car == '&') {
            out += 'ET';
        } else if (car == 'Æ') {
            out += 'AE';
        } else {
            out += car;
        }
    }
    
    return out;
}

 

Remember, this is to produce files where alignment is important, so I can't just replace Æ with AE without fixing the padding instructions (elsewhere).

 

This method uses too many instructions : has anyone got a better way of doing it, still in APEX ?

 

TIA,

Rup