Groovy web console

subscribe to the feed Subscribe
to this
site

Ram

Published 6 months ago by getSystemID with tags SystemID
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def anmapname = "CONNECTIVITY_QODCLNT002_ANY=CONNECTIVITY_DEFAULT_SUPPLIERCON_QODCLNT002_AN02004204493-T_ADDON_ADDON_ANY"
def anReceiverID = "AN02004204493-T"
anmapnamelist = anmapname.split('=');  
anmapvalue = anmapnamelist[1];
  anmapnamelist = anmapvalue.split('_')
  def underscoreCount = anmapnamelist.length;
  anTargetDocumentStandard = anmapnamelist[underscoreCount - 2]
  anTransportProtocol = anmapnamelist[underscoreCount - 3]
  ansys = anmapnamelist[underscoreCount - 5]
  print 'SystemID '+ansys
 
   def beginIndex = findIndexOf(anmapvalue, "_", 3)
   print '\nBegin Index' +beginIndex
   def endIndex = anmapvalue.indexOf("_" + anReceiverID) 
    print '\nEnd Index '+endIndex
    if (endIndex != -1) {
        anSystemID = anmapvalue.substring(beginIndex + 1, endIndex)
     }



def findIndexOf(String conStr, String indexStr, int nthOccurrence) {
 String tempStr = conStr;
 int tempIndex = -1;
 int finalIndex = 0;
 for (int occurrence = 0; occurrence < nthOccurrence; ++occurrence) {
  tempIndex = tempStr.indexOf(indexStr);
  if (tempIndex == -1) {
   break;
  }
  tempStr = tempStr.substring(++tempIndex);
  finalIndex += tempIndex
 }
 finalIndex--;

 return finalIndex;
}