Here is the code...
/* */
/*--------------------------------------------------------------------------------*/
/* */
/* Sorts a CR-LF delineated "toSort" string and returns the string sorted */
/* alphabetically. If parameter "ascendingOrder" is true, sorts in ascending */
/* order, otherwise sorts in descending order. */
/* */
string alphaSort (string toSort, bool ascending) {
string copyOfToSort = toSort
string finishedString = ""
string swapPlaces
int crLfPosition, dummyLength
int numLines = 1
/* Count the number CR-LF's in the string to be sorted */
for (findPlainText(copyOfToSort, "\n", crLfPosition, dummyLength, false)) {
numLines++
copyOfToSort = copyOfToSort[0:crLfPosition-1] copyOfToSort[crLfPosition+1:]
}
/* Parse the string elements into array elements */
copyOfToSort = toSort
string sortArray[numLines]
for (i = 0 ; i < numLines ; i++) {
findPlainText(copyOfToSort, "\n", crLfPosition, dummyLength, false)
if (i < numLines-1) {
sortArray[i] = copyOfToSort[0:crLfPosition-1]
copyOfToSort = copyOfToSort[crLfPosition+1:]
}
else sortArray[i] = copyOfToSort
}
/* Sort the array elements in ascending or descending order */
for (i = 0 ; i < numLines-1 ; i++) {
for (j = i+1 ; j < numLines ; j++) {
if (((upper(sortArray[i]) > upper(sortArray[j])) && ascending) || ((upper(sortArray[i]) < upper(sortArray[j])) && !ascending)) {
swapPlaces = sortArray[i]
sortArray[i] = sortArray[j]
sortArray[j] = swapPlaces
}
}
}
/* Assemble finished string from sortArray, eliminating duplicates */
finishedString = sortArray[0]
for (i = 0 ; i < numLines-1 ; i++) {
if (sortArray[i] != sortArray[i+1]) finishedString = finishedString "\n" sortArray[i+1]
}
if (finishedString[0:0] == "\n") finishedString = finishedString[1:]
if (length(finishedString) > 1) {
if (finishedString[length(finishedString)-1:length(finishedString)-1] == "\n") finishedString = finishedString[0:length(finishedString)-2]
}
return finishedString
}
//-----------------------------------------
// Main routine
string allMessages = ""
string eachMessage
// Each time "eachMessage" takes on a new value, put the following line...
allMessages = allMessages "\n" eachMessage
// When the messages have been assembled, do...
allMessages = alphaSort (allMessages, true)
#Support#DOORS#Sustainability#EngineeringRequirementsManagement#SupportMigration